Mercurial > hg
annotate tests/test-wsgirequest.py @ 38222:507bdc40bb17
run-tests: add support for running specific test cases
Differential Revision: https://phab.mercurial-scm.org/D3555
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Thu, 26 Apr 2018 23:57:20 +0200 |
parents | e0598133ac68 |
children | 2372284d9457 |
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 |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
199 if not getattr(unittest.TestCase, 'assertRaisesRegex', False): |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
200 # Python 3.7 deprecates the regex*p* version, but 2.7 lacks |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
201 # the regex version. |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
202 assertRaisesRegex = (# camelcase-required |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
203 unittest.TestCase.assertRaisesRegexp) |
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
204 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
205 def testreponame(self): |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
206 """repository path components get stripped from URL.""" |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
207 |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
208 with self.assertRaisesRegex(error.ProgrammingError, |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
209 'reponame requires PATH_INFO'): |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
210 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
|
211 |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
212 with self.assertRaisesRegex(error.ProgrammingError, |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
213 'PATH_INFO does not begin with repo ' |
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
214 'name'): |
36897
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'/pathinfo', |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
217 }) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
218 |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
219 with self.assertRaisesRegex(error.ProgrammingError, |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
220 'reponame prefix of PATH_INFO'): |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
221 parse(DEFAULT_ENV, reponame=b'repo', extra={ |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
222 r'PATH_INFO': r'/repoextra/path', |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
223 }) |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
224 |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
225 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
|
226 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
|
227 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
228 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 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
|
233 self.assertEqual(r.apppath, b'/repo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 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
|
235 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
|
236 self.assertEqual(r.reponame, b'repo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
237 |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
238 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
|
239 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
|
240 }) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
241 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
242 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
|
243 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
|
244 self.assertEqual(r.advertisedurl, |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
245 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
|
246 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
|
247 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
|
248 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
|
249 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
|
250 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
|
251 |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
252 def testaltbaseurl(self): |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
253 # Simple hostname remap. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
254 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver') |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
255 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
263 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
264 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
265 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
266 # With a custom port. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
267 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver:8000') |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
268 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
|
269 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
|
270 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
|
271 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
|
272 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
|
273 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
|
274 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
275 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
276 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
277 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
278 # With a changed protocol. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
279 r = parse(DEFAULT_ENV, altbaseurl=b'https://altserver') |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
280 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
|
281 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
|
282 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
|
283 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
|
284 # 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
|
285 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
|
286 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
|
287 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
288 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
289 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
290 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
291 # Need to specify explicit port number for proper https:// alt URLs. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
292 r = parse(DEFAULT_ENV, altbaseurl=b'https://altserver:443') |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
293 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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
300 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
301 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
302 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
303 # With only PATH_INFO defined. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
304 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver', extra={ |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
305 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
|
306 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
307 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
|
308 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
|
309 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
|
310 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
|
311 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
|
312 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
|
313 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
|
314 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
|
315 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
316 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
317 # Path on alt URL. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
318 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver/altpath') |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
319 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
|
320 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
|
321 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
|
322 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
|
323 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
|
324 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
|
325 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
326 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
327 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
328 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
329 # With a trailing slash. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
330 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver/altpath/') |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 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
|
337 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
338 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
339 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
340 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
341 # PATH_INFO + path on alt URL. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
342 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver/altpath', extra={ |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
343 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
|
344 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
345 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
|
346 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
|
347 self.assertEqual(r.advertisedurl, |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
348 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
355 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
356 # PATH_INFO + path on alt URL with trailing slash. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
357 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver/altpath/', extra={ |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
358 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
|
359 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
360 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
|
361 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
|
362 self.assertEqual(r.advertisedurl, |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
370 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
371 # Local SCRIPT_NAME is ignored. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
372 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver', extra={ |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
373 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
|
374 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
|
375 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
385 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
386 # Use remote's path for script name, app path |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
387 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver/altroot', extra={ |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
388 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
|
389 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
|
390 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
391 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
|
392 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
|
393 self.assertEqual(r.advertisedurl, |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
394 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
|
395 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
|
396 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
|
397 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
|
398 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
|
399 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
|
400 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
401 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
402 # 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
|
403 r = parse(DEFAULT_ENV, reponame=b'repo', |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
404 altbaseurl=b'http://altserver/altroot', |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
405 extra={ |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
406 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
|
407 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
|
408 }) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
409 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
410 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
|
411 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
|
412 self.assertEqual(r.advertisedurl, |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
413 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
|
414 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
|
415 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
|
416 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
|
417 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
|
418 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
|
419 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
420 if __name__ == '__main__': |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
421 import silenttestrunner |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
422 silenttestrunner.main(__name__) |