##// 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
16 > import os, sys
17 >
18 > class FileLike(object):
19 > def __init__(self, real):
20 > self.real = real
21 > def fileno(self):
22 > print >> sys.__stdout__, 'FILENO'
23 > return self.real.fileno()
24 > def read(self):
25 > print >> sys.__stdout__, 'READ'
26 > return self.real.read()
27 > def readline(self):
28 > print >> sys.__stdout__, 'READLINE'
29 > return self.real.readline()
30 >
31 > sys.stdin = FileLike(sys.stdin)
32 > errors = StringIO()
33 > input = StringIO()
34 > output = StringIO()
35 >
36 > def startrsp(status, headers):
37 > print '---- STATUS'
38 > print status
39 > print '---- HEADERS'
40 > print [i for i in headers if i[0] != 'ETag']
41 > print '---- DATA'
42 > return output.write
43 >
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
46
77
47 env = {
78 ---- OS.ENVIRON wsgi variables
48 'wsgi.version': (1, 0),
79 []
49 'wsgi.url_scheme': 'http',
80 ---- request.ENVIRON wsgi variables
50 'wsgi.errors': errors,
81 ['wsgi.errors', 'wsgi.input', 'wsgi.multiprocess', 'wsgi.multithread', 'wsgi.run_once', 'wsgi.url_scheme', 'wsgi.version']
51 'wsgi.input': input,
52 'wsgi.multithread': False,
53 'wsgi.multiprocess': False,
54 'wsgi.run_once': False,
55 'REQUEST_METHOD': 'GET',
56 'SCRIPT_NAME': '',
57 'PATH_INFO': '',
58 'QUERY_STRING': '',
59 'SERVER_NAME': '127.0.0.1',
60 'SERVER_PORT': os.environ['HGPORT'],
61 'SERVER_PROTOCOL': 'HTTP/1.0'
62 }
63
64 i = hgweb('.')
65 i(env, startrsp)
66 print '---- ERRORS'
67 print errors.getvalue()
68 print '---- OS.ENVIRON wsgi variables'
69 print sorted([x for x in os.environ if x.startswith('wsgi')])
70 print '---- request.ENVIRON wsgi variables'
71 print sorted([x for x in i.repo.ui.environ if x.startswith('wsgi')])
72 EOF
73
74 python request.py
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