Mercurial > hg
annotate tests/test-wsgirequest.py @ 47067:ea563187ee7c stable
tests: change the fixer commands to use the buffer attribute on stdio objects
Otherwise `\r` was getting injected into the fixed lines and throwing off the
commit hashes on Windows when the fixer is invoked with py3.
Differential Revision: https://phab.mercurial-scm.org/D10637
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Sun, 02 May 2021 16:56:20 -0400 |
parents | 89a2afe31e82 |
children | 6000f5b25c9b |
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): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
52 r = parse( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
53 DEFAULT_ENV, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
54 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
55 'SERVER_PORT': '8000', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
56 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
57 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
58 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
59 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
|
60 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
|
61 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
|
62 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
|
63 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
64 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
65 DEFAULT_ENV, |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
66 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
67 'SERVER_PORT': '4000', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
68 'wsgi.url_scheme': 'https', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
69 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
70 ) |
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'https://testserver:4000') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
77 def testhttphost(self): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
78 r = parse( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
79 DEFAULT_ENV, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
80 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
81 'HTTP_HOST': 'altserver', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
82 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
83 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
84 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 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
|
89 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
90 def testscriptname(self): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
91 r = parse( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
92 DEFAULT_ENV, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
93 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
94 'SCRIPT_NAME': '', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
95 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
96 ) |
36896
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 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
|
99 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
|
100 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
|
101 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
|
102 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
103 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
104 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
105 |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
106 r = parse( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
107 DEFAULT_ENV, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
108 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
109 'SCRIPT_NAME': '/script', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
110 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
111 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
112 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
113 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
|
114 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
|
115 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
|
116 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
|
117 self.assertEqual(r.apppath, b'/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
118 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
119 self.assertIsNone(r.dispatchpath) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
120 |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
121 r = parse( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
122 DEFAULT_ENV, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
123 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
124 'SCRIPT_NAME': '/multiple words', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
125 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
126 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
127 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 self.assertEqual(r.dispatchparts, []) |
36898
d0b0fedbfb53
hgweb: change how dispatch path is reported
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36897
diff
changeset
|
134 self.assertIsNone(r.dispatchpath) |
36896
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 def testpathinfo(self): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
137 r = parse( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
138 DEFAULT_ENV, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
139 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
140 'PATH_INFO': '', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
141 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
142 ) |
36896
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 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
|
145 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
|
146 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
|
147 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
|
148 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
149 self.assertEqual(r.dispatchparts, []) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
150 self.assertEqual(r.dispatchpath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
151 |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
152 r = parse( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
153 DEFAULT_ENV, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
154 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
155 'PATH_INFO': '/pathinfo', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
156 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
157 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
158 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
159 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
|
160 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
|
161 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
|
162 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
|
163 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
164 self.assertEqual(r.dispatchparts, [b'pathinfo']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
165 self.assertEqual(r.dispatchpath, b'pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
166 |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
167 r = parse( |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
168 DEFAULT_ENV, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
169 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
170 'PATH_INFO': '/one/two/', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
171 }, |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
172 ) |
36896
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 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
|
175 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
|
176 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
|
177 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
|
178 self.assertEqual(r.apppath, b'') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
179 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
|
180 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
|
181 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
182 def testscriptandpathinfo(self): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
183 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
184 DEFAULT_ENV, |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
185 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
186 'SCRIPT_NAME': '/script', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
187 'PATH_INFO': '/pathinfo', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
188 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
189 ) |
36896
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://testserver/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://testserver') |
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 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
199 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
200 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
201 extra={ |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
202 'SCRIPT_NAME': '/script1/script2', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
203 'PATH_INFO': '/path1/path2', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
204 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
205 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
206 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
207 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
208 r.url, b'http://testserver/script1/script2/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
209 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
210 self.assertEqual(r.baseurl, b'http://testserver') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
211 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
212 r.advertisedurl, b'http://testserver/script1/script2/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
213 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 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
|
218 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
219 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
220 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
221 extra={ |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
222 'HTTP_HOST': 'hostserver', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
223 'SCRIPT_NAME': '/script', |
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
224 'PATH_INFO': '/pathinfo', |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
225 }, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
226 ) |
36896
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 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
|
229 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
|
230 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
|
231 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
|
232 self.assertEqual(r.apppath, b'/script') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
233 self.assertEqual(r.dispatchparts, [b'pathinfo']) |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
234 self.assertEqual(r.dispatchpath, b'pathinfo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
235 |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
236 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
|
237 # 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
|
238 # the regex version. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
239 assertRaisesRegex = ( # camelcase-required |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
240 unittest.TestCase.assertRaisesRegexp |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
241 ) |
37715
1859b9a7ddef
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp
Augie Fackler <augie@google.com>
parents:
36911
diff
changeset
|
242 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
243 def testreponame(self): |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
244 """repository path components get stripped from URL.""" |
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
245 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
246 with self.assertRaisesRegex( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
247 error.ProgrammingError, 'reponame requires PATH_INFO' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
248 ): |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
249 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
|
250 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
251 with self.assertRaisesRegex( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
252 error.ProgrammingError, 'PATH_INFO does not begin with repo ' 'name' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
253 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
254 parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
255 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
256 reponame=b'repo', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
257 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
258 'PATH_INFO': '/pathinfo', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
259 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
260 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
261 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
262 with self.assertRaisesRegex( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
263 error.ProgrammingError, 'reponame prefix of PATH_INFO' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
264 ): |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
265 parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
266 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
267 reponame=b'repo', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
268 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
269 'PATH_INFO': '/repoextra/path', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
270 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
271 ) |
36897
d7fd203e36cc
hgweb: refactor repository name URL parsing
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36896
diff
changeset
|
272 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
273 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
274 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
275 reponame=b'repo', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
276 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
277 'PATH_INFO': '/repo/path1/path2', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
278 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
279 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
280 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
281 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
|
282 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
|
283 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
|
284 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
|
285 self.assertEqual(r.apppath, b'/repo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
286 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
|
287 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
|
288 self.assertEqual(r.reponame, b'repo') |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
289 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
290 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
291 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
292 reponame=b'prefix/repo', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
293 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
294 'PATH_INFO': '/prefix/repo/path1/path2', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
295 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
296 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
297 |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
298 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
|
299 self.assertEqual(r.baseurl, b'http://testserver') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
300 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
301 r.advertisedurl, b'http://testserver/prefix/repo/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
302 ) |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
303 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
|
304 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
|
305 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
|
306 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
|
307 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
|
308 |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
309 def testaltbaseurl(self): |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
310 # Simple hostname remap. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
311 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
|
312 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
313 self.assertEqual(r.url, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
314 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
315 self.assertEqual(r.advertisedurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
316 self.assertEqual(r.advertisedbaseurl, b'http://altserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
317 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
318 self.assertEqual(r.apppath, b'') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
319 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
320 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
321 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
322 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
323 # With a custom port. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
324 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
|
325 self.assertEqual(r.url, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
326 self.assertEqual(r.baseurl, b'http://testserver') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
327 self.assertEqual(r.advertisedurl, b'http://altserver:8000') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
328 self.assertEqual(r.advertisedbaseurl, b'http://altserver:8000') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
329 self.assertEqual(r.urlscheme, b'http') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
330 self.assertEqual(r.apppath, b'') |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
331 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
332 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
333 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
334 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
335 # With a changed protocol. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
336 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
|
337 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
|
338 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
|
339 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
|
340 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
|
341 # 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
|
342 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
|
343 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
|
344 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
345 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
346 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
347 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
348 # 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
357 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
358 self.assertIsNone(r.reponame) |
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 # With only PATH_INFO defined. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
361 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
362 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
363 altbaseurl=b'http://altserver', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
364 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
365 'PATH_INFO': '/path1/path2', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
366 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
367 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
368 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 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
|
374 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
|
375 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
|
376 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
377 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
378 # Path on alt URL. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 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
|
386 self.assertEqual(r.dispatchparts, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
387 self.assertIsNone(r.dispatchpath) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
388 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
389 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
390 # With a trailing slash. |
37895
e0598133ac68
tests: migrate test-wsgirequest.py to Python 3
Augie Fackler <augie@google.com>
parents:
37715
diff
changeset
|
391 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
|
392 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
|
393 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
|
394 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
|
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'/altpath/') |
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, []) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
399 self.assertIsNone(r.dispatchpath) |
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 # PATH_INFO + path on alt URL. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
403 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
404 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
405 altbaseurl=b'http://altserver/altpath', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
406 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
407 'PATH_INFO': '/path1/path2', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
408 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
409 ) |
36900
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/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') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
412 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
413 r.advertisedurl, b'http://altserver/altpath/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
414 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
415 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
|
416 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
|
417 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
|
418 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
|
419 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
|
420 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
421 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
422 # PATH_INFO + path on alt URL with trailing slash. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
423 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
424 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
425 altbaseurl=b'http://altserver/altpath/', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
426 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
427 'PATH_INFO': '/path1/path2', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
428 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
429 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
430 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
|
431 self.assertEqual(r.baseurl, b'http://testserver') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
432 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
433 r.advertisedurl, b'http://altserver/altpath//path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
434 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
435 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
|
436 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
|
437 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
|
438 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
|
439 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
|
440 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
441 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
442 # Local SCRIPT_NAME is ignored. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
443 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
444 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
445 altbaseurl=b'http://altserver', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
446 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
447 'SCRIPT_NAME': '/script', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
448 'PATH_INFO': '/path1/path2', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
449 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
450 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
451 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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
460 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
461 # Use remote's path for script name, app path |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
462 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
463 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
464 altbaseurl=b'http://altserver/altroot', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
465 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
466 'SCRIPT_NAME': '/script', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
467 'PATH_INFO': '/path1/path2', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
468 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
469 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
470 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
|
471 self.assertEqual(r.baseurl, b'http://testserver') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
472 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
473 r.advertisedurl, b'http://altserver/altroot/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
474 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
475 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
|
476 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
|
477 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
|
478 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
|
479 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
|
480 self.assertIsNone(r.reponame) |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
481 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
482 # reponame is factored in properly. |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
483 r = parse( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
484 DEFAULT_ENV, |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
485 reponame=b'repo', |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
486 altbaseurl=b'http://altserver/altroot', |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
487 extra={ |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
488 'SCRIPT_NAME': '/script', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
489 'PATH_INFO': '/repo/path1/path2', |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
45004
diff
changeset
|
490 }, |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
491 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
492 |
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
493 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
|
494 self.assertEqual(r.baseurl, b'http://testserver') |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
495 self.assertEqual( |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
496 r.advertisedurl, b'http://altserver/altroot/repo/path1/path2' |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
497 ) |
36900
219b23359f4c
hgweb: support constructing URLs from an alternate base URL
Gregory Szorc <gregory.szorc@gmail.com>
parents:
36898
diff
changeset
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 |
45004
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
504 def testenvencoding(self): |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
505 if pycompat.iswindows: |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
506 # 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
|
507 # are supported. |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
508 r = parse(DEFAULT_ENV, extra={'foo': 'bar'}) |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
509 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
|
510 else: |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
511 # 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
|
512 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
|
513 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
|
514 self.assertEqual(r.rawenv[b'foo'], b) |
2632c1ed8f34
hgweb: encode WSGI environment like OS environment
Manuel Jacob <me@manueljacob.de>
parents:
43506
diff
changeset
|
515 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
516 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
517 if __name__ == '__main__': |
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
518 import silenttestrunner |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
37895
diff
changeset
|
519 |
36896
b2a3308d6a21
tests: add test coverage for parsing WSGI requests
Gregory Szorc <gregory.szorc@gmail.com>
parents:
diff
changeset
|
520 silenttestrunner.main(__name__) |