summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlastimil Zíma <ziima@users.noreply.github.com>2020-03-02 18:33:35 +0100
committerGitHub <noreply@github.com>2020-03-02 18:33:35 +0100
commitffe009db773defd7b2b8832778f488a23c8f7ca7 (patch)
tree3cd0a5144c03602a128aed39b7a8b425f27992d5
parent557dc2eac99b29feda2c7f207f7ad6cbe90dde09 (diff)
parent3f71c33a4b907a8120468e2f22da1d4a15824d90 (diff)
downloadopenid-ffe009db773defd7b2b8832778f488a23c8f7ca7.tar.gz
Merge pull request #39 from cjwatson/fix-tests
Fix failing tests
-rw-r--r--openid/test/test_cryptutil.py33
-rw-r--r--openid/test/test_fetchers.py14
2 files changed, 28 insertions, 19 deletions
diff --git a/openid/test/test_cryptutil.py b/openid/test/test_cryptutil.py
index 106be42..f0caed5 100644
--- a/openid/test/test_cryptutil.py
+++ b/openid/test/test_cryptutil.py
@@ -5,6 +5,7 @@ import os.path
import random
import sys
import unittest
+import warnings
import six
@@ -18,15 +19,17 @@ class TestLongBinary(unittest.TestCase):
def test_binaryLongConvert(self):
MAX = sys.maxsize
- for iteration in range(500):
- n = 0
- for i in range(10):
- n += random.randrange(MAX)
-
- s = cryptutil.longToBinary(n)
- assert isinstance(s, six.binary_type)
- n_prime = cryptutil.binaryToLong(s)
- assert n == n_prime, (n, n_prime)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ for iteration in range(500):
+ n = 0
+ for i in range(10):
+ n += random.randrange(MAX)
+
+ s = cryptutil.longToBinary(n)
+ assert isinstance(s, six.binary_type)
+ n_prime = cryptutil.binaryToLong(s)
+ assert n == n_prime, (n, n_prime)
cases = [
(b'\x00', 0),
@@ -39,11 +42,13 @@ class TestLongBinary(unittest.TestCase):
(b'OpenID is cool', 1611215304203901150134421257416556)
]
- for s, n in cases:
- n_prime = cryptutil.binaryToLong(s)
- s_prime = cryptutil.longToBinary(n)
- assert n == n_prime, (s, n, n_prime)
- assert s == s_prime, (n, s, s_prime)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', category=DeprecationWarning)
+ for s, n in cases:
+ n_prime = cryptutil.binaryToLong(s)
+ s_prime = cryptutil.longToBinary(n)
+ assert n == n_prime, (s, n, n_prime)
+ assert s == s_prime, (n, s, s_prime)
class TestFixBtwoc(unittest.TestCase):
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):