##// END OF EJS Templates
tests: unify test-hgweb-non-interactive
Matt Mackall -
r12440:d9f7753a default
parent child Browse files
Show More
@@ -1,74 +1,81 b''
1 #!/bin/sh
1 Tests if hgweb can run without touching sys.stdin, as is required
2 # Tests if hgweb can run without touching sys.stdin, as is required
2 by the WSGI standard and strictly implemented by mod_wsgi.
3 # by the WSGI standard and strictly implemented by mod_wsgi.
4
5 mkdir repo
6 cd repo
7 hg init
8 echo foo > bar
9 hg add bar
10 hg commit -m "test"
11 hg tip
12
13 cat > request.py <<EOF
14 from mercurial import dispatch
15 from mercurial.hgweb.hgweb_mod import hgweb
16 from mercurial.ui import ui
17 from mercurial import hg
18 from StringIO import StringIO
19 import os, sys
20
21 class FileLike(object):
22 def __init__(self, real):
23 self.real = real
24 def fileno(self):
25 print >> sys.__stdout__, 'FILENO'
26 return self.real.fileno()
27 def read(self):
28 print >> sys.__stdout__, 'READ'
29 return self.real.read()
30 def readline(self):
31 print >> sys.__stdout__, 'READLINE'
32 return self.real.readline()
33
3
34 sys.stdin = FileLike(sys.stdin)
4 $ mkdir repo
35 errors = StringIO()
5 $ cd repo
36 input = StringIO()
6 $ hg init
37 output = StringIO()
7 $ echo foo > bar
38
8 $ hg add bar
39 def startrsp(status, headers):
9 $ hg commit -m "test"
40 print '---- STATUS'
10 $ cat > request.py <<EOF
41 print status
11 > from mercurial import dispatch
42 print '---- HEADERS'
12 > from mercurial.hgweb.hgweb_mod import hgweb
43 print [i for i in headers if i[0] != 'ETag']
13 > from mercurial.ui import ui
44 print '---- DATA'
14 > from mercurial import hg
45 return output.write
15 > from StringIO import StringIO
46
16 > import os, sys
47 env = {
17 >
48 'wsgi.version': (1, 0),
18 > class FileLike(object):
49 'wsgi.url_scheme': 'http',
19 > def __init__(self, real):
50 'wsgi.errors': errors,
20 > self.real = real
51 'wsgi.input': input,
21 > def fileno(self):
52 'wsgi.multithread': False,
22 > print >> sys.__stdout__, 'FILENO'
53 'wsgi.multiprocess': False,
23 > return self.real.fileno()
54 'wsgi.run_once': False,
24 > def read(self):
55 'REQUEST_METHOD': 'GET',
25 > print >> sys.__stdout__, 'READ'
56 'SCRIPT_NAME': '',
26 > return self.real.read()
57 'PATH_INFO': '',
27 > def readline(self):
58 'QUERY_STRING': '',
28 > print >> sys.__stdout__, 'READLINE'
59 'SERVER_NAME': '127.0.0.1',
29 > return self.real.readline()
60 'SERVER_PORT': os.environ['HGPORT'],
30 >
61 'SERVER_PROTOCOL': 'HTTP/1.0'
31 > sys.stdin = FileLike(sys.stdin)
62 }
32 > errors = StringIO()
63
33 > input = StringIO()
64 i = hgweb('.')
34 > output = StringIO()
65 i(env, startrsp)
35 >
66 print '---- ERRORS'
36 > def startrsp(status, headers):
67 print errors.getvalue()
37 > print '---- STATUS'
68 print '---- OS.ENVIRON wsgi variables'
38 > print status
69 print sorted([x for x in os.environ if x.startswith('wsgi')])
39 > print '---- HEADERS'
70 print '---- request.ENVIRON wsgi variables'
40 > print [i for i in headers if i[0] != 'ETag']
71 print sorted([x for x in i.repo.ui.environ if x.startswith('wsgi')])
41 > print '---- DATA'
72 EOF
42 > return output.write
73
43 >
74 python request.py
44 > env = {
45 > 'wsgi.version': (1, 0),
46 > 'wsgi.url_scheme': 'http',
47 > 'wsgi.errors': errors,
48 > 'wsgi.input': input,
49 > 'wsgi.multithread': False,
50 > 'wsgi.multiprocess': False,
51 > 'wsgi.run_once': False,
52 > 'REQUEST_METHOD': 'GET',
53 > 'SCRIPT_NAME': '',
54 > 'PATH_INFO': '',
55 > 'QUERY_STRING': '',
56 > 'SERVER_NAME': '127.0.0.1',
57 > 'SERVER_PORT': os.environ['HGPORT'],
58 > 'SERVER_PROTOCOL': 'HTTP/1.0'
59 > }
60 >
61 > i = hgweb('.')
62 > i(env, startrsp)
63 > print '---- ERRORS'
64 > print errors.getvalue()
65 > print '---- OS.ENVIRON wsgi variables'
66 > print sorted([x for x in os.environ if x.startswith('wsgi')])
67 > print '---- request.ENVIRON wsgi variables'
68 > print sorted([x for x in i.repo.ui.environ if x.startswith('wsgi')])
69 > EOF
70 $ python request.py
71 ---- STATUS
72 200 Script output follows
73 ---- HEADERS
74 [('Content-Type', 'text/html; charset=ascii')]
75 ---- DATA
76 ---- ERRORS
77
78 ---- OS.ENVIRON wsgi variables
79 []
80 ---- request.ENVIRON wsgi variables
81 ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version']
1 NO CONTENT: file was removed
NO CONTENT: file was removed
General Comments 0
You need to be logged in to leave comments. Login now