Mercurial > hg
annotate tests/test-wsgirequest.py @ 45774:450e17e59603
commit: leverage cmdutil.check_incompatible_arguments()
Differential Revision: https://phab.mercurial-scm.org/D9218
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Thu, 15 Oct 2020 22:23:02 -0700 |
parents | 2632c1ed8f34 |
children | 89a2afe31e82 |
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 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
5 from mercurial.hgweb import request as requestmod |
45004
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
6 from mercurial import error, pycompat |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
7 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
8 DEFAULT_ENV = { |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
9 'REQUEST_METHOD': 'GET', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
10 'SERVER_NAME': 'testserver', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
11 'SERVER_PORT': '80', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
12 'SERVER_PROTOCOL': 'http', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
13 'wsgi.version': (1, 0), |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
14 'wsgi.url_scheme': 'http', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
15 'wsgi.input': None, |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
16 'wsgi.errors': None, |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
17 'wsgi.multithread': False, |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
18 'wsgi.multiprocess': True, |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
19 'wsgi.run_once': False, |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
20 } |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
21 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
22 |
36911
f0a851542a05
hgweb: remove wsgirequest (API)
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36900
diff
changeset
|
23 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
|
24 env = dict(env) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
25 env.update(extra or {}) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
26 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
27 return requestmod.parserequestfromenv( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
28 env, reponame=reponame, altbaseurl=altbaseurl |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
29 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
30 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
31 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
32 class ParseRequestTests(unittest.TestCase): |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
33 def testdefault(self): |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
34 r = parse(DEFAULT_ENV) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
35 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
|
36 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
|
37 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
|
38 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
|
39 self.assertEqual(r.urlscheme, b'http') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
40 self.assertEqual(r.method, b'GET') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
41 self.assertIsNone(r.remoteuser) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
42 self.assertIsNone(r.remotehost) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
43 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
44 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
45 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
46 self.assertIsNone(r.reponame) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
47 self.assertEqual(r.querystring, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
48 self.assertEqual(len(r.qsparams), 0) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
49 self.assertEqual(len(r.headers), 0) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
50 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
51 def testcustomport(self): |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
52 r = parse(DEFAULT_ENV, extra={'SERVER_PORT': '8000',}) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
53 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
54 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
|
55 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
|
56 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
|
57 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
|
58 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
59 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
60 DEFAULT_ENV, |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
61 extra={'SERVER_PORT': '4000', 'wsgi.url_scheme': 'https',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
62 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
63 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
64 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
|
65 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
|
66 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
|
67 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
|
68 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
69 def testhttphost(self): |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
70 r = parse(DEFAULT_ENV, extra={'HTTP_HOST': 'altserver',}) |
36896
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 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
|
73 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
|
74 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
|
75 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
|
76 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 def testscriptname(self): |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
78 r = parse(DEFAULT_ENV, extra={'SCRIPT_NAME': '',}) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
79 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 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
|
84 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
86 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
87 |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
88 r = parse(DEFAULT_ENV, extra={'SCRIPT_NAME': '/script',}) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
89 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 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
|
91 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
|
92 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
|
93 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
|
94 self.assertEqual(r.apppath, b'/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
95 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
96 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
97 |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
98 r = parse(DEFAULT_ENV, extra={'SCRIPT_NAME': '/multiple words',}) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
99 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
100 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
|
101 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
|
102 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
|
103 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
|
104 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
|
105 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
106 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
107 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
108 def testpathinfo(self): |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
109 r = parse(DEFAULT_ENV, extra={'PATH_INFO': '',}) |
36896
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') |
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') |
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'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
116 self.assertEqual(r.dispatchparts, []) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
117 self.assertEqual(r.dispatchpath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
119 r = parse(DEFAULT_ENV, extra={'PATH_INFO': '/pathinfo',}) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
121 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
|
122 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
|
123 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
|
124 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
|
125 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
126 self.assertEqual(r.dispatchparts, [b'pathinfo']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 self.assertEqual(r.dispatchpath, b'pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
129 r = parse(DEFAULT_ENV, extra={'PATH_INFO': '/one/two/',}) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
130 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
131 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
|
132 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
|
133 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
|
134 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
|
135 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
136 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
|
137 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
|
138 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
139 def testscriptandpathinfo(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
140 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
141 DEFAULT_ENV, |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
142 extra={'SCRIPT_NAME': '/script', 'PATH_INFO': '/pathinfo',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
143 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
144 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
145 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
|
146 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
|
147 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
|
148 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
|
149 self.assertEqual(r.apppath, b'/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 self.assertEqual(r.dispatchparts, [b'pathinfo']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 self.assertEqual(r.dispatchpath, b'pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
152 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
153 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
154 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
155 extra={ |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
156 'SCRIPT_NAME': '/script1/script2', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
157 'PATH_INFO': '/path1/path2', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
158 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
159 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
160 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
161 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
162 r.url, b'http://testserver/script1/script2/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
163 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
164 self.assertEqual(r.baseurl, b'http://testserver') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
165 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
166 r.advertisedurl, b'http://testserver/script1/script2/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
167 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 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
|
172 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
173 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
174 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
175 extra={ |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
176 'HTTP_HOST': 'hostserver', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
177 'SCRIPT_NAME': '/script', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
178 'PATH_INFO': '/pathinfo', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
179 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
180 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
181 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 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
|
183 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
|
184 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
|
185 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
|
186 self.assertEqual(r.apppath, b'/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
187 self.assertEqual(r.dispatchparts, [b'pathinfo']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
188 self.assertEqual(r.dispatchpath, b'pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
189 |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
190 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
|
191 # 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
|
192 # the regex version. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
193 assertRaisesRegex = ( # camelcase-required |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
194 unittest.TestCase.assertRaisesRegexp |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
195 ) |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
196 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
197 def testreponame(self): |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
198 """repository path components get stripped from URL.""" |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
199 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
200 with self.assertRaisesRegex( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
201 error.ProgrammingError, 'reponame requires PATH_INFO' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
202 ): |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
203 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
|
204 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
205 with self.assertRaisesRegex( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
206 error.ProgrammingError, 'PATH_INFO does not begin with repo ' 'name' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
207 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
208 parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
209 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
210 reponame=b'repo', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
211 extra={'PATH_INFO': '/pathinfo',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
212 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
213 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
214 with self.assertRaisesRegex( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
215 error.ProgrammingError, 'reponame prefix of PATH_INFO' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
216 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
217 parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
218 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
219 reponame=b'repo', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
220 extra={'PATH_INFO': '/repoextra/path',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
221 ) |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
222 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
223 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
224 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
225 reponame=b'repo', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
226 extra={'PATH_INFO': '/repo/path1/path2',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
227 ) |
36896
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 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
238 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
239 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
240 reponame=b'prefix/repo', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
241 extra={'PATH_INFO': '/prefix/repo/path1/path2',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
242 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
244 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
|
245 self.assertEqual(r.baseurl, b'http://testserver') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
246 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
247 r.advertisedurl, b'http://testserver/prefix/repo/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
248 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
249 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
|
250 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
|
251 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
|
252 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
|
253 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
|
254 |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
255 def testaltbaseurl(self): |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
256 # Simple hostname remap. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
257 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
|
258 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
266 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
267 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
268 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
269 # With a custom port. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
270 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
|
271 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
278 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
279 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
280 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
281 # With a changed protocol. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
282 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
|
283 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
|
284 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
|
285 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
|
286 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
|
287 # 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
|
288 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
|
289 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
|
290 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
291 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
292 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
293 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
294 # 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 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
|
300 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
|
301 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
|
302 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
303 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
304 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
305 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
306 # With only PATH_INFO defined. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
307 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
308 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
309 altbaseurl=b'http://altserver', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
310 extra={'PATH_INFO': '/path1/path2',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
311 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 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
|
320 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
321 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
322 # Path on alt URL. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
323 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
|
324 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
|
325 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
|
326 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
|
327 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
|
328 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
|
329 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
|
330 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
331 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
332 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
333 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
334 # With a trailing slash. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
335 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
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 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
|
342 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
343 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
344 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
345 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
346 # PATH_INFO + path on alt URL. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
347 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
348 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
349 altbaseurl=b'http://altserver/altpath', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
350 extra={'PATH_INFO': '/path1/path2',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
351 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
352 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
|
353 self.assertEqual(r.baseurl, b'http://testserver') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
354 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
355 r.advertisedurl, b'http://altserver/altpath/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
356 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
357 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
|
358 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
|
359 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
|
360 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
|
361 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
|
362 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
363 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
364 # PATH_INFO + path on alt URL with trailing slash. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
365 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
366 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
367 altbaseurl=b'http://altserver/altpath/', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
368 extra={'PATH_INFO': '/path1/path2',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
369 ) |
36900
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/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') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
372 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
373 r.advertisedurl, b'http://altserver/altpath//path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
374 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
375 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
|
376 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
|
377 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
|
378 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
|
379 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
|
380 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
381 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
382 # Local SCRIPT_NAME is ignored. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
383 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
384 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
385 altbaseurl=b'http://altserver', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
386 extra={'SCRIPT_NAME': '/script', 'PATH_INFO': '/path1/path2',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
387 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
388 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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 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
|
395 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
|
396 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
397 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
398 # Use remote's path for script name, app path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
399 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
400 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
401 altbaseurl=b'http://altserver/altroot', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
402 extra={'SCRIPT_NAME': '/script', 'PATH_INFO': '/path1/path2',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
403 ) |
36900
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/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') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
406 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
407 r.advertisedurl, b'http://altserver/altroot/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
408 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
415 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
416 # reponame is factored in properly. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
417 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
418 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
419 reponame=b'repo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
420 altbaseurl=b'http://altserver/altroot', |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
421 extra={'SCRIPT_NAME': '/script', 'PATH_INFO': '/repo/path1/path2',}, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
422 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
423 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
424 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
|
425 self.assertEqual(r.baseurl, b'http://testserver') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
426 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
427 r.advertisedurl, b'http://altserver/altroot/repo/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
428 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 |
45004
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
435 def testenvencoding(self): |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
436 if pycompat.iswindows: |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
437 # On Windows, we can't generally know which non-ASCII characters |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
438 # are supported. |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
439 r = parse(DEFAULT_ENV, extra={'foo': 'bar'}) |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
440 self.assertEqual(r.rawenv[b'foo'], b'bar') |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
441 else: |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
442 # Unix is byte-based. Therefore we test all possible bytes. |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
443 b = b''.join(pycompat.bytechr(i) for i in range(256)) |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
444 r = parse(DEFAULT_ENV, extra={'foo': pycompat.fsdecode(b)}) |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
445 self.assertEqual(r.rawenv[b'foo'], b) |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
446 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
447 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
448 if __name__ == '__main__': |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
449 import silenttestrunner |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
450 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
451 silenttestrunner.main(__name__) |