summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2018-03-27 08:20:44 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2018-04-05 12:38:49 (GMT)
commit8252e948e7a9e4f487f1049fd28d5ef3f938486b (patch)
tree84f987372c29c309becc76c573a90265740f685d
parent1e02302fd9c651f9f98c737e930acb2dbe835bef (diff)
downloaddjango-mellon-8252e948e7a9e4f487f1049fd28d5ef3f938486b.zip
django-mellon-8252e948e7a9e4f487f1049fd28d5ef3f938486b.tar.gz
django-mellon-8252e948e7a9e4f487f1049fd28d5ef3f938486b.tar.bz2
tests: adapt to python 3
-rw-r--r--tests/test_sso_slo.py7
-rw-r--r--tests/test_views.py15
2 files changed, 14 insertions, 8 deletions
diff --git a/tests/test_sso_slo.py b/tests/test_sso_slo.py
index 795e53d..f69131e 100644
--- a/tests/test_sso_slo.py
+++ b/tests/test_sso_slo.py
@@ -3,6 +3,7 @@ import lasso
from pytest import fixture
from django.core.urlresolvers import reverse
+from django.utils import six
from mellon.utils import create_metadata
@@ -128,7 +129,11 @@ def test_sso_request_denied(db, app, idp, caplog, sp_settings):
url, body = idp.process_authn_request_redirect(response['Location'], auth_result=False)
assert url.endswith(reverse('mellon_login'))
response = app.post(reverse('mellon_login'), params={'SAMLResponse': body})
- assert "status is not success codes: [u'urn:oasis:names:tc:SAML:2.0:status:Responder',\
+ if six.PY3:
+ assert "status is not success codes: ['urn:oasis:names:tc:SAML:2.0:status:Responder',\
+ 'urn:oasis:names:tc:SAML:2.0:status:RequestDenied']" in caplog.text
+ else:
+ assert "status is not success codes: [u'urn:oasis:names:tc:SAML:2.0:status:Responder',\
u'urn:oasis:names:tc:SAML:2.0:status:RequestDenied']" in caplog.text
diff --git a/tests/test_views.py b/tests/test_views.py
index f50c3b0..9292de7 100644
--- a/tests/test_views.py
+++ b/tests/test_views.py
@@ -8,6 +8,7 @@ import hashlib
from httmock import HTTMock
from django.core.urlresolvers import reverse
+from django.utils.encoding import force_text
from django.utils.http import urlencode
from xml_utils import assert_xml_constraints
@@ -125,7 +126,7 @@ def test_sp_initiated_login_improperly_configured2(private_settings, client):
private_settings.MELLON_IDENTITY_PROVIDERS = []
response = client.get('/login/')
assert response.status_code == 400
- assert 'no idp found' in response.content
+ assert b'no idp found' in response.content
def test_sp_initiated_login_discovery_service(private_settings, client):
@@ -154,7 +155,7 @@ def test_sp_initiated_login_discovery_service_nodisco(private_settings, client):
private_settings.MELLON_DISCOVERY_SERVICE_URL = 'https://disco'
response = client.get('/login/?nodisco=1')
assert response.status_code == 400
- assert 'no idp found' in response.content
+ assert b'no idp found' in response.content
def test_sp_initiated_login(private_settings, client):
@@ -199,7 +200,7 @@ def test_sp_initiated_login_requested_authn_context(private_settings, client):
assert response.status_code == 302
params = parse_qs(urlparse(response['Location']).query)
assert response['Location'].startswith('http://idp5/singleSignOn?')
- assert params.keys() == ['SAMLRequest']
+ assert list(params.keys()) == ['SAMLRequest']
assert len(params['SAMLRequest']) == 1
assert base64.b64decode(params['SAMLRequest'][0])
request = lasso.Samlp2AuthnRequest()
@@ -213,15 +214,15 @@ def test_malfortmed_artifact(private_settings, client, caplog):
'METADATA': open('tests/metadata.xml').read(),
}]
response = client.get('/login/?SAMLart=xxx', status=400)
- assert 'artifact is malformed' in response.content
+ assert b'artifact is malformed' in response.content
assert 'artifact is malformed' in caplog.text
@pytest.fixture
def artifact():
- entity_id = 'http://idp5/metadata'
- token = 'x' * 20
- return base64.b64encode('\x00\x04\x00\x00' + hashlib.sha1(entity_id).digest() + token)
+ entity_id = b'http://idp5/metadata'
+ token = b'x' * 20
+ return force_text(base64.b64encode(b'\x00\x04\x00\x00' + hashlib.sha1(entity_id).digest() + token))
def test_error_500_on_artifact_resolve(private_settings, client, caplog, artifact):