From 3f71c33a4b907a8120468e2f22da1d4a15824d90 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Mon, 2 Mar 2020 11:47:54 +0100 Subject: 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. --- openid/test/test_fetchers.py | 14 +++++++++----- 1 file 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): -- cgit v1.2.1