launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26381
[Merge] ~cjwatson/launchpad:py3-test-basic-launchpad-request into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-test-basic-launchpad-request into launchpad:master.
Commit message:
Fix TestBasicLaunchpadRequest for Python 3
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398390
test_baserequest_recovers_from_bad_path_info_encoding is only relevant on Python 2, due to the string handling requirements of PEP 3333. Add another test to exercise the Unicode case.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-test-basic-launchpad-request into launchpad:master.
diff --git a/lib/lp/services/webapp/tests/test_servers.py b/lib/lp/services/webapp/tests/test_servers.py
index 3087ca4..adfd1a6 100644
--- a/lib/lp/services/webapp/tests/test_servers.py
+++ b/lib/lp/services/webapp/tests/test_servers.py
@@ -395,12 +395,25 @@ class TestBasicLaunchpadRequest(TestCase):
def test_baserequest_recovers_from_bad_path_info_encoding(self):
# The request object recodes PATH_INFO to ensure sane_environment
# does not raise a UnicodeDecodeError when LaunchpadBrowserRequest
- # is instantiated.
- bad_path = 'fnord/trunk\xE4'
+ # is instantiated. This is only relevant on Python 2: PATH_INFO is
+ # required to be a native string, which on Python 3 is already
+ # Unicode, so the recoding issue doesn't arise.
+ bad_path = b'fnord/trunk\xE4'
env = {'PATH_INFO': bad_path}
request = LaunchpadBrowserRequest(io.BytesIO(b''), env)
self.assertEqual(u'fnord/trunk\ufffd', request.getHeader('PATH_INFO'))
+ def test_baserequest_preserves_path_info_unicode(self):
+ # If the request object receives PATH_INFO as Unicode, it is passed
+ # through unchanged. This is only relevant on Python 3: PATH_INFO
+ # is required to be a native string, which on Python 2 is bytes.
+ # (As explained in BasicLaunchpadRequest.__init__, non-ASCII
+ # characters will be rejected later during traversal.)
+ bad_path = u'fnord/trunk\xE4'
+ env = {'PATH_INFO': bad_path}
+ request = LaunchpadBrowserRequest(io.BytesIO(b''), env)
+ self.assertEqual(u'fnord/trunk\xE4', request.getHeader('PATH_INFO'))
+
def test_request_with_invalid_query_string_recovers(self):
# When the query string has invalid utf-8, it is decoded with
# replacement.