diff options
author | Colin Watson <cjwatson@debian.org> | 2020-03-02 11:47:54 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2020-03-02 11:47:54 +0100 |
commit | 3f71c33a4b907a8120468e2f22da1d4a15824d90 (patch) | |
tree | 3cd0a5144c03602a128aed39b7a8b425f27992d5 | |
parent | 2c0d6f05ed118e64097ee9d0e1237a18c066c9e3 (diff) | |
download | openid-3f71c33a4b907a8120468e2f22da1d4a15824d90.tar.gz |
Fix TestRequestsFetcher failures
`responses` needs the content type to be set using the `content_type`
keyword argument; using `headers` for this results in responses with
`Content-Type: text/plain, text/plain`.
test_invalid_url needs a slight adjustment to pass on Python 2, due to
the different `repr` for text strings.
-rw-r--r-- | openid/test/test_fetchers.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/openid/test/test_fetchers.py b/openid/test/test_fetchers.py index d7b03d1..1989340 100644 --- a/openid/test/test_fetchers.py +++ b/openid/test/test_fetchers.py @@ -401,7 +401,7 @@ class TestRequestsFetcher(unittest.TestCase): # Test GET response with responses.RequestsMock() as rsps: rsps.add(responses.GET, 'http://example.cz/', status=200, body=b'BODY', - headers={'Content-Type': 'text/plain'}) + content_type='text/plain') response = self.fetcher.fetch('http://example.cz/') expected = fetchers.HTTPResponse('http://example.cz/', 200, {'Content-Type': 'text/plain'}, b'BODY') assertResponse(expected, response) @@ -410,7 +410,7 @@ class TestRequestsFetcher(unittest.TestCase): # Test POST response with responses.RequestsMock() as rsps: rsps.add(responses.POST, 'http://example.cz/', status=200, body=b'BODY', - headers={'Content-Type': 'text/plain'}) + content_type='text/plain') response = self.fetcher.fetch('http://example.cz/', body=b'key=value') expected = fetchers.HTTPResponse('http://example.cz/', 200, {'Content-Type': 'text/plain'}, b'BODY') assertResponse(expected, response) @@ -421,7 +421,7 @@ class TestRequestsFetcher(unittest.TestCase): rsps.add(responses.GET, 'http://example.cz/redirect/', status=302, headers={'Location': 'http://example.cz/target/'}) rsps.add(responses.GET, 'http://example.cz/target/', status=200, body=b'BODY', - headers={'Content-Type': 'text/plain'}) + content_type='text/plain') response = self.fetcher.fetch('http://example.cz/redirect/') expected = fetchers.HTTPResponse('http://example.cz/target/', 200, {'Content-Type': 'text/plain'}, b'BODY') assertResponse(expected, response) @@ -430,14 +430,18 @@ class TestRequestsFetcher(unittest.TestCase): # Test error responses - returned as obtained with responses.RequestsMock() as rsps: rsps.add(responses.GET, 'http://example.cz/error/', status=500, body=b'BODY', - headers={'Content-Type': 'text/plain'}) + content_type='text/plain') response = self.fetcher.fetch('http://example.cz/error/') expected = fetchers.HTTPResponse('http://example.cz/error/', 500, {'Content-Type': 'text/plain'}, b'BODY') assertResponse(expected, response) def test_invalid_url(self): invalid_url = 'invalid://example.cz/' - with six.assertRaisesRegex(self, InvalidSchema, "No connection adapters were found for '" + invalid_url + "'"): + expected_message = ( + 'No connection adapters were found for ' + + ('u' if six.PY2 else '') + + "'" + invalid_url + "'") + with six.assertRaisesRegex(self, InvalidSchema, expected_message): self.fetcher.fetch(invalid_url) def test_connection_error(self): |