Mercurial > hg
annotate tests/test-wsgirequest.py @ 37289:5fadc63ac99f
wireproto: explicit API to create outgoing streams
It is better to create outgoing streams through the reactor so the
reactor knows about what streams are active and can track them
accordingly.
Test output changes slightly because frames from subsequent responses
no longer have the "stream begin" stream flag set because the stream
is now used across all responses.
Differential Revision: https://phab.mercurial-scm.org/D2947
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 26 Mar 2018 13:59:56 -0700 |
parents | f0a851542a05 |
children | 1859b9a7ddef |
rev | line source |
---|---|
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
1 from __future__ import absolute_import, print_function |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
2 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
3 import unittest |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
4 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
5 from mercurial.hgweb import ( |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
6 request as requestmod, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 ) |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
8 from mercurial import ( |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
9 error, |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
10 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
11 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
12 DEFAULT_ENV = { |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
13 r'REQUEST_METHOD': r'GET', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
14 r'SERVER_NAME': r'testserver', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
15 r'SERVER_PORT': r'80', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
16 r'SERVER_PROTOCOL': r'http', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
17 r'wsgi.version': (1, 0), |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
18 r'wsgi.url_scheme': r'http', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
19 r'wsgi.input': None, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 r'wsgi.errors': None, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 r'wsgi.multithread': False, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
22 r'wsgi.multiprocess': True, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
23 r'wsgi.run_once': False, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
24 } |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36900
diff
changeset
|
26 def parse(env, reponame=None, altbaseurl=None, extra=None): |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
27 env = dict(env) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
28 env.update(extra or {}) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
29 |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36900
diff
changeset
|
30 return requestmod.parserequestfromenv(env, reponame=reponame, |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
31 altbaseurl=altbaseurl) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 class ParseRequestTests(unittest.TestCase): |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 def testdefault(self): |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 r = parse(DEFAULT_ENV) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
36 self.assertEqual(r.url, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
37 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
38 self.assertEqual(r.advertisedurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
39 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 self.assertEqual(r.urlscheme, b'http') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 self.assertEqual(r.method, b'GET') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 self.assertIsNone(r.remoteuser) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 self.assertIsNone(r.remotehost) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
45 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
46 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 self.assertIsNone(r.reponame) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 self.assertEqual(r.querystring, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 self.assertEqual(len(r.qsparams), 0) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 self.assertEqual(len(r.headers), 0) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
52 def testcustomport(self): |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 r'SERVER_PORT': r'8000', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
55 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
56 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
57 self.assertEqual(r.url, b'http://testserver:8000') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 self.assertEqual(r.baseurl, b'http://testserver:8000') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 self.assertEqual(r.advertisedurl, b'http://testserver:8000') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
60 self.assertEqual(r.advertisedbaseurl, b'http://testserver:8000') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
61 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
62 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 r'SERVER_PORT': r'4000', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 r'wsgi.url_scheme': r'https', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
65 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
66 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
67 self.assertEqual(r.url, b'https://testserver:4000') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
68 self.assertEqual(r.baseurl, b'https://testserver:4000') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 self.assertEqual(r.advertisedurl, b'https://testserver:4000') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
70 self.assertEqual(r.advertisedbaseurl, b'https://testserver:4000') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
71 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
72 def testhttphost(self): |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
74 r'HTTP_HOST': r'altserver', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
75 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
76 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 self.assertEqual(r.url, b'http://altserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
78 self.assertEqual(r.baseurl, b'http://altserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 self.assertEqual(r.advertisedurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
81 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
82 def testscriptname(self): |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
83 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 r'SCRIPT_NAME': r'', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
86 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 self.assertEqual(r.url, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
88 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 self.assertEqual(r.advertisedurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
91 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
92 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
93 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
94 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
96 r'SCRIPT_NAME': r'/script', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
98 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 self.assertEqual(r.url, b'http://testserver/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
101 self.assertEqual(r.advertisedurl, b'http://testserver/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
102 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 self.assertEqual(r.apppath, b'/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
104 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
105 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
106 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 r'SCRIPT_NAME': r'/multiple words', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
109 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
110 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
111 self.assertEqual(r.url, b'http://testserver/multiple%20words') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 self.assertEqual(r.advertisedurl, b'http://testserver/multiple%20words') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
114 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
115 self.assertEqual(r.apppath, b'/multiple words') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
117 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
119 def testpathinfo(self): |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 r'PATH_INFO': r'', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
122 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
123 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
124 self.assertEqual(r.url, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
125 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 self.assertEqual(r.advertisedurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
129 self.assertEqual(r.dispatchparts, []) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 self.assertEqual(r.dispatchpath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
132 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
133 r'PATH_INFO': r'/pathinfo', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
134 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
135 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 self.assertEqual(r.url, b'http://testserver/pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
137 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
138 self.assertEqual(r.advertisedurl, b'http://testserver/pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
139 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
140 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
141 self.assertEqual(r.dispatchparts, [b'pathinfo']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
142 self.assertEqual(r.dispatchpath, b'pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
143 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
144 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
145 r'PATH_INFO': r'/one/two/', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
146 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
147 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
148 self.assertEqual(r.url, b'http://testserver/one/two/') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 self.assertEqual(r.advertisedurl, b'http://testserver/one/two/') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
153 self.assertEqual(r.dispatchparts, [b'one', b'two']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
154 self.assertEqual(r.dispatchpath, b'one/two') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
155 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
156 def testscriptandpathinfo(self): |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
157 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
158 r'SCRIPT_NAME': r'/script', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
159 r'PATH_INFO': r'/pathinfo', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
161 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
162 self.assertEqual(r.url, b'http://testserver/script/pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
163 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
164 self.assertEqual(r.advertisedurl, b'http://testserver/script/pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
165 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
166 self.assertEqual(r.apppath, b'/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
167 self.assertEqual(r.dispatchparts, [b'pathinfo']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 self.assertEqual(r.dispatchpath, b'pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
169 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
170 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
171 r'SCRIPT_NAME': r'/script1/script2', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
172 r'PATH_INFO': r'/path1/path2', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
173 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
174 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
175 self.assertEqual(r.url, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
176 b'http://testserver/script1/script2/path1/path2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
177 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
178 self.assertEqual(r.advertisedurl, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
179 b'http://testserver/script1/script2/path1/path2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
180 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 self.assertEqual(r.apppath, b'/script1/script2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 self.assertEqual(r.dispatchparts, [b'path1', b'path2']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
183 self.assertEqual(r.dispatchpath, b'path1/path2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
184 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
185 r = parse(DEFAULT_ENV, extra={ |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
186 r'HTTP_HOST': r'hostserver', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 r'SCRIPT_NAME': r'/script', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 r'PATH_INFO': r'/pathinfo', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
190 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
191 self.assertEqual(r.url, b'http://hostserver/script/pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
192 self.assertEqual(r.baseurl, b'http://hostserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
193 self.assertEqual(r.advertisedurl, b'http://testserver/script/pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
194 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
195 self.assertEqual(r.apppath, b'/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
196 self.assertEqual(r.dispatchparts, [b'pathinfo']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 self.assertEqual(r.dispatchpath, b'pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
198 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
199 def testreponame(self): |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
200 """repository path components get stripped from URL.""" |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
201 |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
202 with self.assertRaisesRegexp(error.ProgrammingError, |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
203 b'reponame requires PATH_INFO'): |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
204 parse(DEFAULT_ENV, reponame=b'repo') |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
206 with self.assertRaisesRegexp(error.ProgrammingError, |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
207 b'PATH_INFO does not begin with repo ' |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
208 b'name'): |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
209 parse(DEFAULT_ENV, reponame=b'repo', extra={ |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
210 r'PATH_INFO': r'/pathinfo', |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
211 }) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
212 |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
213 with self.assertRaisesRegexp(error.ProgrammingError, |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
214 b'reponame prefix of PATH_INFO'): |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
215 parse(DEFAULT_ENV, reponame=b'repo', extra={ |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
216 r'PATH_INFO': r'/repoextra/path', |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
217 }) |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
218 |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
219 r = parse(DEFAULT_ENV, reponame=b'repo', extra={ |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
220 r'PATH_INFO': r'/repo/path1/path2', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
221 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
222 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
223 self.assertEqual(r.url, b'http://testserver/repo/path1/path2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
224 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
225 self.assertEqual(r.advertisedurl, b'http://testserver/repo/path1/path2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
226 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
227 self.assertEqual(r.apppath, b'/repo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
228 self.assertEqual(r.dispatchparts, [b'path1', b'path2']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 self.assertEqual(r.dispatchpath, b'path1/path2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
230 self.assertEqual(r.reponame, b'repo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
231 |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
232 r = parse(DEFAULT_ENV, reponame=b'prefix/repo', extra={ |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 r'PATH_INFO': r'/prefix/repo/path1/path2', |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
236 self.assertEqual(r.url, b'http://testserver/prefix/repo/path1/path2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 self.assertEqual(r.baseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
238 self.assertEqual(r.advertisedurl, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
239 b'http://testserver/prefix/repo/path1/path2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
240 self.assertEqual(r.advertisedbaseurl, b'http://testserver') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 self.assertEqual(r.apppath, b'/prefix/repo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 self.assertEqual(r.dispatchparts, [b'path1', b'path2']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 self.assertEqual(r.dispatchpath, b'path1/path2') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
244 self.assertEqual(r.reponame, b'prefix/repo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
245 |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
246 def testaltbaseurl(self): |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
247 # Simple hostname remap. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
248 r = parse(DEFAULT_ENV, altbaseurl='http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
249 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
250 self.assertEqual(r.url, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
251 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
252 self.assertEqual(r.advertisedurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
253 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
254 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
255 self.assertEqual(r.apppath, b'') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
256 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
257 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
258 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
259 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
260 # With a custom port. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
261 r = parse(DEFAULT_ENV, altbaseurl='http://altserver:8000') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
262 self.assertEqual(r.url, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
263 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
264 self.assertEqual(r.advertisedurl, b'http://altserver:8000') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
265 self.assertEqual(r.advertisedbaseurl, b'http://altserver:8000') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
266 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
267 self.assertEqual(r.apppath, b'') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
268 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
269 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
270 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
271 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
272 # With a changed protocol. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
273 r = parse(DEFAULT_ENV, altbaseurl='https://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
274 self.assertEqual(r.url, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
275 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
276 self.assertEqual(r.advertisedurl, b'https://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
277 self.assertEqual(r.advertisedbaseurl, b'https://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
278 # URL scheme is defined as the actual scheme, not advertised. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
279 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
280 self.assertEqual(r.apppath, b'') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
281 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
282 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
283 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
284 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
285 # Need to specify explicit port number for proper https:// alt URLs. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
286 r = parse(DEFAULT_ENV, altbaseurl='https://altserver:443') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
287 self.assertEqual(r.url, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
288 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
289 self.assertEqual(r.advertisedurl, b'https://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
290 self.assertEqual(r.advertisedbaseurl, b'https://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
291 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
292 self.assertEqual(r.apppath, b'') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
293 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
294 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
295 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
296 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
297 # With only PATH_INFO defined. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
298 r = parse(DEFAULT_ENV, altbaseurl='http://altserver', extra={ |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
299 r'PATH_INFO': r'/path1/path2', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
300 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
301 self.assertEqual(r.url, b'http://testserver/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
302 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
303 self.assertEqual(r.advertisedurl, b'http://altserver/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
304 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
305 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
306 self.assertEqual(r.apppath, b'') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
307 self.assertEqual(r.dispatchparts, [b'path1', b'path2']) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
308 self.assertEqual(r.dispatchpath, b'path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
309 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
310 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
311 # Path on alt URL. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
312 r = parse(DEFAULT_ENV, altbaseurl='http://altserver/altpath') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
313 self.assertEqual(r.url, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
314 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
315 self.assertEqual(r.advertisedurl, b'http://altserver/altpath') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
316 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
317 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
318 self.assertEqual(r.apppath, b'/altpath') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
319 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
320 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
321 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
322 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
323 # With a trailing slash. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
324 r = parse(DEFAULT_ENV, altbaseurl='http://altserver/altpath/') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
325 self.assertEqual(r.url, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
326 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
327 self.assertEqual(r.advertisedurl, b'http://altserver/altpath/') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
328 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
329 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
330 self.assertEqual(r.apppath, b'/altpath/') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
331 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
332 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
333 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
334 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
335 # PATH_INFO + path on alt URL. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
336 r = parse(DEFAULT_ENV, altbaseurl='http://altserver/altpath', extra={ |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
337 r'PATH_INFO': r'/path1/path2', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
338 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
339 self.assertEqual(r.url, b'http://testserver/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
340 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
341 self.assertEqual(r.advertisedurl, |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
342 b'http://altserver/altpath/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
343 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
344 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
345 self.assertEqual(r.apppath, b'/altpath') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
346 self.assertEqual(r.dispatchparts, [b'path1', b'path2']) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
347 self.assertEqual(r.dispatchpath, b'path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
348 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
349 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
350 # PATH_INFO + path on alt URL with trailing slash. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
351 r = parse(DEFAULT_ENV, altbaseurl='http://altserver/altpath/', extra={ |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
352 r'PATH_INFO': r'/path1/path2', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
353 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
354 self.assertEqual(r.url, b'http://testserver/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
355 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
356 self.assertEqual(r.advertisedurl, |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
357 b'http://altserver/altpath//path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
358 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
359 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
360 self.assertEqual(r.apppath, b'/altpath/') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
361 self.assertEqual(r.dispatchparts, [b'path1', b'path2']) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
362 self.assertEqual(r.dispatchpath, b'path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
363 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
364 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
365 # Local SCRIPT_NAME is ignored. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
366 r = parse(DEFAULT_ENV, altbaseurl='http://altserver', extra={ |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
367 r'SCRIPT_NAME': r'/script', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
368 r'PATH_INFO': r'/path1/path2', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
369 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
370 self.assertEqual(r.url, b'http://testserver/script/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
371 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
372 self.assertEqual(r.advertisedurl, b'http://altserver/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
373 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
374 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
375 self.assertEqual(r.apppath, b'') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
376 self.assertEqual(r.dispatchparts, [b'path1', b'path2']) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
377 self.assertEqual(r.dispatchpath, b'path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
378 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
379 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
380 # Use remote's path for script name, app path |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
381 r = parse(DEFAULT_ENV, altbaseurl='http://altserver/altroot', extra={ |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
382 r'SCRIPT_NAME': r'/script', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
383 r'PATH_INFO': r'/path1/path2', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
384 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
385 self.assertEqual(r.url, b'http://testserver/script/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
386 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
387 self.assertEqual(r.advertisedurl, |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
388 b'http://altserver/altroot/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
389 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
390 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
391 self.assertEqual(r.apppath, b'/altroot') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
392 self.assertEqual(r.dispatchparts, [b'path1', b'path2']) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
393 self.assertEqual(r.dispatchpath, b'path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
394 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
395 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
396 # reponame is factored in properly. |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
397 r = parse(DEFAULT_ENV, reponame=b'repo', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
398 altbaseurl='http://altserver/altroot', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
399 extra={ |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
400 r'SCRIPT_NAME': r'/script', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
401 r'PATH_INFO': r'/repo/path1/path2', |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
402 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
403 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
404 self.assertEqual(r.url, b'http://testserver/script/repo/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
405 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
406 self.assertEqual(r.advertisedurl, |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
407 b'http://altserver/altroot/repo/path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
408 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
409 self.assertEqual(r.apppath, b'/altroot/repo') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
410 self.assertEqual(r.dispatchparts, [b'path1', b'path2']) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
411 self.assertEqual(r.dispatchpath, b'path1/path2') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
412 self.assertEqual(r.reponame, b'repo') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
413 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
414 if __name__ == '__main__': |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
415 import silenttestrunner |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
416 silenttestrunner.main(__name__) |