##// END OF EJS Templates
errors: stop passing non-strings to Abort's constructor...
errors: stop passing non-strings to Abort's constructor The next patch will change `Abort`'s constructor and `__bytes__` functions and they will start assuming that the first argument is the messages as `bytes`. Differential Revision: https://phab.mercurial-scm.org/D9178

File last commit:

r45541:2632c1ed stable
r46273:a736ab68 default
Show More
test-wsgirequest.py
451 lines | 18.1 KiB | text/x-python | PythonLexer
/ tests / test-wsgirequest.py
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 from __future__ import absolute_import, print_function
import unittest
Augie Fackler
formatting: blacken the codebase...
r43346 from mercurial.hgweb import request as requestmod
Manuel Jacob
hgweb: encode WSGI environment like OS environment...
r45541 from mercurial import error, pycompat
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
DEFAULT_ENV = {
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 'REQUEST_METHOD': 'GET',
'SERVER_NAME': 'testserver',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'http',
'wsgi.version': (1, 0),
'wsgi.url_scheme': 'http',
'wsgi.input': None,
'wsgi.errors': None,
'wsgi.multithread': False,
'wsgi.multiprocess': True,
'wsgi.run_once': False,
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 }
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
hgweb: remove wsgirequest (API)...
r36928 def parse(env, reponame=None, altbaseurl=None, extra=None):
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 env = dict(env)
env.update(extra or {})
Augie Fackler
formatting: blacken the codebase...
r43346 return requestmod.parserequestfromenv(
env, reponame=reponame, altbaseurl=altbaseurl
)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
class ParseRequestTests(unittest.TestCase):
def testdefault(self):
r = parse(DEFAULT_ENV)
self.assertEqual(r.url, b'http://testserver')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://testserver')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.method, b'GET')
self.assertIsNone(r.remoteuser)
self.assertIsNone(r.remotehost)
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [])
Gregory Szorc
hgweb: change how dispatch path is reported...
r36914 self.assertIsNone(r.dispatchpath)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 self.assertIsNone(r.reponame)
self.assertEqual(r.querystring, b'')
self.assertEqual(len(r.qsparams), 0)
self.assertEqual(len(r.headers), 0)
def testcustomport(self):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 r = parse(DEFAULT_ENV, extra={'SERVER_PORT': '8000',})
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver:8000')
self.assertEqual(r.baseurl, b'http://testserver:8000')
self.assertEqual(r.advertisedurl, b'http://testserver:8000')
self.assertEqual(r.advertisedbaseurl, b'http://testserver:8000')
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'SERVER_PORT': '4000', 'wsgi.url_scheme': 'https',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'https://testserver:4000')
self.assertEqual(r.baseurl, b'https://testserver:4000')
self.assertEqual(r.advertisedurl, b'https://testserver:4000')
self.assertEqual(r.advertisedbaseurl, b'https://testserver:4000')
def testhttphost(self):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 r = parse(DEFAULT_ENV, extra={'HTTP_HOST': 'altserver',})
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://altserver')
self.assertEqual(r.baseurl, b'http://altserver')
self.assertEqual(r.advertisedurl, b'http://testserver')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
def testscriptname(self):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 r = parse(DEFAULT_ENV, extra={'SCRIPT_NAME': '',})
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://testserver')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [])
Gregory Szorc
hgweb: change how dispatch path is reported...
r36914 self.assertIsNone(r.dispatchpath)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 r = parse(DEFAULT_ENV, extra={'SCRIPT_NAME': '/script',})
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver/script')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://testserver/script')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'/script')
self.assertEqual(r.dispatchparts, [])
Gregory Szorc
hgweb: change how dispatch path is reported...
r36914 self.assertIsNone(r.dispatchpath)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 r = parse(DEFAULT_ENV, extra={'SCRIPT_NAME': '/multiple words',})
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver/multiple%20words')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://testserver/multiple%20words')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'/multiple words')
self.assertEqual(r.dispatchparts, [])
Gregory Szorc
hgweb: change how dispatch path is reported...
r36914 self.assertIsNone(r.dispatchpath)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
def testpathinfo(self):
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 r = parse(DEFAULT_ENV, extra={'PATH_INFO': '',})
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://testserver')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [])
self.assertEqual(r.dispatchpath, b'')
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 r = parse(DEFAULT_ENV, extra={'PATH_INFO': '/pathinfo',})
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver/pathinfo')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://testserver/pathinfo')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [b'pathinfo'])
self.assertEqual(r.dispatchpath, b'pathinfo')
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 r = parse(DEFAULT_ENV, extra={'PATH_INFO': '/one/two/',})
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver/one/two/')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://testserver/one/two/')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [b'one', b'two'])
self.assertEqual(r.dispatchpath, b'one/two')
def testscriptandpathinfo(self):
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'SCRIPT_NAME': '/script', 'PATH_INFO': '/pathinfo',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver/script/pathinfo')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://testserver/script/pathinfo')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'/script')
self.assertEqual(r.dispatchparts, [b'pathinfo'])
self.assertEqual(r.dispatchpath, b'pathinfo')
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
extra={
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 'SCRIPT_NAME': '/script1/script2',
'PATH_INFO': '/path1/path2',
Augie Fackler
formatting: blacken the codebase...
r43346 },
)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
Augie Fackler
formatting: blacken the codebase...
r43346 self.assertEqual(
r.url, b'http://testserver/script1/script2/path1/path2'
)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 self.assertEqual(r.baseurl, b'http://testserver')
Augie Fackler
formatting: blacken the codebase...
r43346 self.assertEqual(
r.advertisedurl, b'http://testserver/script1/script2/path1/path2'
)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'/script1/script2')
self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
self.assertEqual(r.dispatchpath, b'path1/path2')
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
extra={
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 'HTTP_HOST': 'hostserver',
'SCRIPT_NAME': '/script',
'PATH_INFO': '/pathinfo',
Augie Fackler
formatting: blacken the codebase...
r43346 },
)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://hostserver/script/pathinfo')
self.assertEqual(r.baseurl, b'http://hostserver')
self.assertEqual(r.advertisedurl, b'http://testserver/script/pathinfo')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'/script')
self.assertEqual(r.dispatchparts, [b'pathinfo'])
self.assertEqual(r.dispatchpath, b'pathinfo')
Augie Fackler
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp...
r37733 if not getattr(unittest.TestCase, 'assertRaisesRegex', False):
# Python 3.7 deprecates the regex*p* version, but 2.7 lacks
# the regex version.
Augie Fackler
formatting: blacken the codebase...
r43346 assertRaisesRegex = ( # camelcase-required
unittest.TestCase.assertRaisesRegexp
)
Augie Fackler
cleanup: polyfill assertRaisesRegex so we can avoid assertRaisesRegexp...
r37733
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 def testreponame(self):
Gregory Szorc
hgweb: refactor repository name URL parsing...
r36913 """repository path components get stripped from URL."""
Augie Fackler
formatting: blacken the codebase...
r43346 with self.assertRaisesRegex(
error.ProgrammingError, 'reponame requires PATH_INFO'
):
Gregory Szorc
hgweb: refactor repository name URL parsing...
r36913 parse(DEFAULT_ENV, reponame=b'repo')
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
Augie Fackler
formatting: blacken the codebase...
r43346 with self.assertRaisesRegex(
error.ProgrammingError, 'PATH_INFO does not begin with repo ' 'name'
):
parse(
DEFAULT_ENV,
reponame=b'repo',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'PATH_INFO': '/pathinfo',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
Augie Fackler
formatting: blacken the codebase...
r43346 with self.assertRaisesRegex(
error.ProgrammingError, 'reponame prefix of PATH_INFO'
):
parse(
DEFAULT_ENV,
reponame=b'repo',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'PATH_INFO': '/repoextra/path',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
hgweb: refactor repository name URL parsing...
r36913
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
reponame=b'repo',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'PATH_INFO': '/repo/path1/path2',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver/repo/path1/path2')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://testserver/repo/path1/path2')
self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'/repo')
self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
self.assertEqual(r.dispatchpath, b'path1/path2')
self.assertEqual(r.reponame, b'repo')
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
reponame=b'prefix/repo',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'PATH_INFO': '/prefix/repo/path1/path2',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912
self.assertEqual(r.url, b'http://testserver/prefix/repo/path1/path2')
self.assertEqual(r.baseurl, b'http://testserver')
Augie Fackler
formatting: blacken the codebase...
r43346 self.assertEqual(
r.advertisedurl, b'http://testserver/prefix/repo/path1/path2'
)
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 self.assertEqual(r.advertisedbaseurl, b'http://testserver')
self.assertEqual(r.apppath, b'/prefix/repo')
self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
self.assertEqual(r.dispatchpath, b'path1/path2')
self.assertEqual(r.reponame, b'prefix/repo')
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 def testaltbaseurl(self):
# Simple hostname remap.
Augie Fackler
tests: migrate test-wsgirequest.py to Python 3...
r37912 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver')
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916
self.assertEqual(r.url, b'http://testserver')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://altserver')
self.assertEqual(r.advertisedbaseurl, b'http://altserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [])
self.assertIsNone(r.dispatchpath)
self.assertIsNone(r.reponame)
# With a custom port.
Augie Fackler
tests: migrate test-wsgirequest.py to Python 3...
r37912 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver:8000')
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://altserver:8000')
self.assertEqual(r.advertisedbaseurl, b'http://altserver:8000')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [])
self.assertIsNone(r.dispatchpath)
self.assertIsNone(r.reponame)
# With a changed protocol.
Augie Fackler
tests: migrate test-wsgirequest.py to Python 3...
r37912 r = parse(DEFAULT_ENV, altbaseurl=b'https://altserver')
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'https://altserver')
self.assertEqual(r.advertisedbaseurl, b'https://altserver')
# URL scheme is defined as the actual scheme, not advertised.
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [])
self.assertIsNone(r.dispatchpath)
self.assertIsNone(r.reponame)
# Need to specify explicit port number for proper https:// alt URLs.
Augie Fackler
tests: migrate test-wsgirequest.py to Python 3...
r37912 r = parse(DEFAULT_ENV, altbaseurl=b'https://altserver:443')
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'https://altserver')
self.assertEqual(r.advertisedbaseurl, b'https://altserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [])
self.assertIsNone(r.dispatchpath)
self.assertIsNone(r.reponame)
# With only PATH_INFO defined.
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
altbaseurl=b'http://altserver',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'PATH_INFO': '/path1/path2',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver/path1/path2')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://altserver/path1/path2')
self.assertEqual(r.advertisedbaseurl, b'http://altserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
self.assertEqual(r.dispatchpath, b'path1/path2')
self.assertIsNone(r.reponame)
# Path on alt URL.
Augie Fackler
tests: migrate test-wsgirequest.py to Python 3...
r37912 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver/altpath')
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://altserver/altpath')
self.assertEqual(r.advertisedbaseurl, b'http://altserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'/altpath')
self.assertEqual(r.dispatchparts, [])
self.assertIsNone(r.dispatchpath)
self.assertIsNone(r.reponame)
# With a trailing slash.
Augie Fackler
tests: migrate test-wsgirequest.py to Python 3...
r37912 r = parse(DEFAULT_ENV, altbaseurl=b'http://altserver/altpath/')
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://altserver/altpath/')
self.assertEqual(r.advertisedbaseurl, b'http://altserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'/altpath/')
self.assertEqual(r.dispatchparts, [])
self.assertIsNone(r.dispatchpath)
self.assertIsNone(r.reponame)
# PATH_INFO + path on alt URL.
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
altbaseurl=b'http://altserver/altpath',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'PATH_INFO': '/path1/path2',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver/path1/path2')
self.assertEqual(r.baseurl, b'http://testserver')
Augie Fackler
formatting: blacken the codebase...
r43346 self.assertEqual(
r.advertisedurl, b'http://altserver/altpath/path1/path2'
)
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.advertisedbaseurl, b'http://altserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'/altpath')
self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
self.assertEqual(r.dispatchpath, b'path1/path2')
self.assertIsNone(r.reponame)
# PATH_INFO + path on alt URL with trailing slash.
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
altbaseurl=b'http://altserver/altpath/',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'PATH_INFO': '/path1/path2',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver/path1/path2')
self.assertEqual(r.baseurl, b'http://testserver')
Augie Fackler
formatting: blacken the codebase...
r43346 self.assertEqual(
r.advertisedurl, b'http://altserver/altpath//path1/path2'
)
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.advertisedbaseurl, b'http://altserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'/altpath/')
self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
self.assertEqual(r.dispatchpath, b'path1/path2')
self.assertIsNone(r.reponame)
# Local SCRIPT_NAME is ignored.
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
altbaseurl=b'http://altserver',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'SCRIPT_NAME': '/script', 'PATH_INFO': '/path1/path2',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver/script/path1/path2')
self.assertEqual(r.baseurl, b'http://testserver')
self.assertEqual(r.advertisedurl, b'http://altserver/path1/path2')
self.assertEqual(r.advertisedbaseurl, b'http://altserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'')
self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
self.assertEqual(r.dispatchpath, b'path1/path2')
self.assertIsNone(r.reponame)
# Use remote's path for script name, app path
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
altbaseurl=b'http://altserver/altroot',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'SCRIPT_NAME': '/script', 'PATH_INFO': '/path1/path2',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.url, b'http://testserver/script/path1/path2')
self.assertEqual(r.baseurl, b'http://testserver')
Augie Fackler
formatting: blacken the codebase...
r43346 self.assertEqual(
r.advertisedurl, b'http://altserver/altroot/path1/path2'
)
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.advertisedbaseurl, b'http://altserver')
self.assertEqual(r.urlscheme, b'http')
self.assertEqual(r.apppath, b'/altroot')
self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
self.assertEqual(r.dispatchpath, b'path1/path2')
self.assertIsNone(r.reponame)
# reponame is factored in properly.
Augie Fackler
formatting: blacken the codebase...
r43346 r = parse(
DEFAULT_ENV,
reponame=b'repo',
altbaseurl=b'http://altserver/altroot',
Augie Fackler
cleanup: remove pointless r-prefixes on single-quoted strings...
r43906 extra={'SCRIPT_NAME': '/script', 'PATH_INFO': '/repo/path1/path2',},
Augie Fackler
formatting: blacken the codebase...
r43346 )
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916
self.assertEqual(r.url, b'http://testserver/script/repo/path1/path2')
self.assertEqual(r.baseurl, b'http://testserver')
Augie Fackler
formatting: blacken the codebase...
r43346 self.assertEqual(
r.advertisedurl, b'http://altserver/altroot/repo/path1/path2'
)
Gregory Szorc
hgweb: support constructing URLs from an alternate base URL...
r36916 self.assertEqual(r.advertisedbaseurl, b'http://altserver')
self.assertEqual(r.apppath, b'/altroot/repo')
self.assertEqual(r.dispatchparts, [b'path1', b'path2'])
self.assertEqual(r.dispatchpath, b'path1/path2')
self.assertEqual(r.reponame, b'repo')
Manuel Jacob
hgweb: encode WSGI environment like OS environment...
r45541 def testenvencoding(self):
if pycompat.iswindows:
# On Windows, we can't generally know which non-ASCII characters
# are supported.
r = parse(DEFAULT_ENV, extra={'foo': 'bar'})
self.assertEqual(r.rawenv[b'foo'], b'bar')
else:
# Unix is byte-based. Therefore we test all possible bytes.
b = b''.join(pycompat.bytechr(i) for i in range(256))
r = parse(DEFAULT_ENV, extra={'foo': pycompat.fsdecode(b)})
self.assertEqual(r.rawenv[b'foo'], b)
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 if __name__ == '__main__':
import silenttestrunner
Augie Fackler
formatting: blacken the codebase...
r43346
Gregory Szorc
tests: add test coverage for parsing WSGI requests...
r36912 silenttestrunner.main(__name__)