summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Kanakarakis <ivan.kanak@gmail.com>2019-07-08 21:14:54 +0300
committerIvan Kanakarakis <ivan.kanak@gmail.com>2019-07-08 21:14:54 +0300
commit124376b3a707edf354fcc2e7311a86af864cf647 (patch)
treec95dce6d8ad14ff995f18b7a06e8006d29a677c7
parent5a435953afbc71405c777ab658d9fc1394931277 (diff)
downloadpysaml2-124376b3a707edf354fcc2e7311a86af864cf647.tar.gz
Fix tests to be compatible with latest pytest
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
-rw-r--r--tests/test_02_saml.py2
-rw-r--r--tests/test_03_saml2.py14
-rw-r--r--tests/test_12_s_utils.py5
-rw-r--r--tests/test_13_validate.py31
-rw-r--r--tests/test_20_assertion.py17
-rw-r--r--tests/test_31_config.py1
-rw-r--r--tests/test_32_cache.py8
-rw-r--r--tests/test_36_mdbcache.py15
-rw-r--r--tests/test_40_sigver.py16
-rw-r--r--tests/test_50_server.py10
-rw-r--r--tests/test_51_client.py45
11 files changed, 100 insertions, 64 deletions
diff --git a/tests/test_02_saml.py b/tests/test_02_saml.py
index 8ab6ca04..fe5bbb70 100644
--- a/tests/test_02_saml.py
+++ b/tests/test_02_saml.py
@@ -19,7 +19,7 @@ from saml2 import xmldsig as ds
from saml2 import saml
-from py.test import raises
+from pytest import raises
from saml2.saml import Issuer
from saml2.saml import Attribute
diff --git a/tests/test_03_saml2.py b/tests/test_03_saml2.py
index a71eb3cd..442884af 100644
--- a/tests/test_03_saml2.py
+++ b/tests/test_03_saml2.py
@@ -7,7 +7,7 @@ from saml2.saml import NameID, Issuer, SubjectLocality, AuthnContextClassRef
from saml2.saml import SubjectConfirmationData, SubjectConfirmation
from saml2.saml import Attribute
-from py.test import raises
+from pytest import raises
import saml2_data
try:
@@ -28,7 +28,7 @@ ITEMS = {
</NameID>
""", """<?xml version="1.0" encoding="utf-8"?>
<NameID xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
- SPNameQualifier="https://foo.example.com/sp"
+ SPNameQualifier="https://foo.example.com/sp"
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">_1632879f09d08ea5ede2dc667cbed7e429ebc4335c</NameID>
""", """<?xml version="1.0" encoding="utf-8"?>
<NameID xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
@@ -48,9 +48,9 @@ SPNameQualifier="http://auth.example.com/saml/metadata">test
SubjectConfirmationData:
"""<?xml version="1.0" encoding="utf-8"?>
<SubjectConfirmationData xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
-InResponseTo="_1683146e27983964fbe7bf8f08961108d166a652e5"
-NotOnOrAfter="2010-02-18T13:52:13.959Z"
-NotBefore="2010-01-16T12:00:00Z"
+InResponseTo="_1683146e27983964fbe7bf8f08961108d166a652e5"
+NotOnOrAfter="2010-02-18T13:52:13.959Z"
+NotBefore="2010-01-16T12:00:00Z"
Recipient="http://192.168.0.10/saml/sp" />""",
SubjectConfirmation:
"""<?xml version="1.0" encoding="utf-8"?>
@@ -176,7 +176,7 @@ def test_create_class_from_xml_string_xxe():
]>
<lolz>&lol1;</lolz>
"""
- with raises(EntitiesForbidden) as err:
+ with raises(EntitiesForbidden):
create_class_from_xml_string(NameID, xml)
@@ -207,7 +207,7 @@ def test_ee_2():
def test_ee_3():
ee = saml2.extension_element_from_string(
"""<?xml version='1.0' encoding='UTF-8'?>
- <foo xmlns="urn:mace:example.com:saml:ns"
+ <foo xmlns="urn:mace:example.com:saml:ns"
id="xyz">bar</foo>""")
assert ee != None
print(ee.__dict__)
diff --git a/tests/test_12_s_utils.py b/tests/test_12_s_utils.py
index c0293c55..cd1be8e9 100644
--- a/tests/test_12_s_utils.py
+++ b/tests/test_12_s_utils.py
@@ -14,10 +14,9 @@ from saml2.s_utils import do_attribute_statement
from saml2.saml import Attribute, Subject
from saml2.saml import NAME_FORMAT_URI
-from py.test import raises
-
from pathutils import full_path
+
XML_HEADER = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n'
SUCCESS_STATUS_NO_HEADER = (
@@ -64,7 +63,7 @@ def _oeq(l1, l2):
def test_inflate_then_deflate():
txt = """Selma Lagerlöf (1858-1940) was born in Östra Emterwik, Värmland,
- Sweden. She was brought up on Mårbacka, the family estate, which she did
+ Sweden. She was brought up on Mårbacka, the family estate, which she did
not leave until 1881, when she went to a teachers' college at Stockholm"""
if not isinstance(txt, six.binary_type):
txt = txt.encode('utf-8')
diff --git a/tests/test_13_validate.py b/tests/test_13_validate.py
index 5bf94157..ba85e6cb 100644
--- a/tests/test_13_validate.py
+++ b/tests/test_13_validate.py
@@ -14,7 +14,7 @@ from saml2.validate import valid_any_uri
from saml2.validate import NotValid
from saml2.validate import valid_anytype
-from py.test import raises
+from pytest import raises
def _eq(l1, l2):
@@ -33,23 +33,30 @@ def test_duration():
assert valid_duration("-P1347M")
assert valid_duration("P1Y2MT2.5H")
- raises(NotValid, 'valid_duration("P-1347M")')
- raises(NotValid, ' valid_duration("P1Y2MT")')
- raises(NotValid, ' valid_duration("P1Y2MT2xH")')
+ with raises(NotValid):
+ valid_duration("P-1347M")
+ with raises(NotValid):
+ valid_duration("P1Y2MT")
+ with raises(NotValid):
+ valid_duration("P1Y2MT2xH")
def test_unsigned_short():
assert valid_unsigned_short("1234")
- raises(NotValid, ' valid_unsigned_short("-1234")')
- raises(NotValid, ' valid_unsigned_short("1234567890")')
+ with raises(NotValid):
+ valid_unsigned_short("-1234")
+ with raises(NotValid):
+ valid_unsigned_short("1234567890")
def test_valid_non_negative_integer():
assert valid_non_negative_integer("1234567890")
- raises(NotValid, 'valid_non_negative_integer("-123")')
- raises(NotValid, 'valid_non_negative_integer("123.56")')
+ with raises(NotValid):
+ valid_non_negative_integer("-123")
+ with raises(NotValid):
+ valid_non_negative_integer("123.56")
assert valid_non_negative_integer("12345678901234567890")
@@ -58,9 +65,8 @@ def test_valid_string():
import codecs
- raises(NotValid,
- 'valid_string(codecs.getdecoder("hex_codec")'
- '(b"02656c6c6f")[0].decode("utf-8"))')
+ with raises(NotValid):
+ valid_string(codecs.getdecoder("hex_codec")(b"02656c6c6f")[0].decode("utf-8"))
def test_valid_anyuri():
@@ -102,7 +108,8 @@ def test_valid_instance():
response.status = samlp.Status()
response.assertion.append(saml.Assertion())
- raises(MustValueError, 'valid_instance(response)')
+ with raises(MustValueError):
+ valid_instance(response)
def test_valid_anytype():
diff --git a/tests/test_20_assertion.py b/tests/test_20_assertion.py
index 1c04f18a..88be13f6 100644
--- a/tests/test_20_assertion.py
+++ b/tests/test_20_assertion.py
@@ -1,6 +1,4 @@
# coding=utf-8
-import pytest
-
from saml2.argtree import add_path
from saml2.authn_context import pword
from saml2.mdie import to_dict
@@ -21,7 +19,7 @@ from saml2.s_utils import MissingValue
from saml2 import attribute_converter
from saml2.attribute_converter import ac_factory, AttributeConverterNOOP
-from py.test import raises
+from pytest import raises
from saml2.extension import mdui
from saml2.extension import idpdisc
@@ -82,7 +80,7 @@ def test_filter_on_attributes_1():
def test_filter_on_attributes_2():
-
+
a = to_dict(Attribute(friendly_name="surName",name="urn:oid:2.5.4.4",
name_format=NAME_FORMAT_URI), ONTS)
required = [a]
@@ -117,7 +115,7 @@ def test_filter_on_attributes_with_missing_required_attribute():
friendly_name="eduPersonTargetedID",
name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10",
name_format=NAME_FORMAT_URI), ONTS)
- with pytest.raises(MissingValue):
+ with raises(MissingValue):
filter_on_attributes(ava, required=[eptid], acs=ac_factory())
@@ -441,7 +439,8 @@ def test_filter_values_req_2():
required = [a1, a2]
ava = {"serialNumber": ["12345"], "givenName": ["Lars"]}
- raises(MissingValue, filter_on_attributes, ava, required, acs=ac_factory())
+ with raises(MissingValue):
+ filter_on_attributes(ava, required, acs=ac_factory())
def test_filter_values_req_3():
@@ -467,7 +466,8 @@ def test_filter_values_req_4():
required = [a]
ava = {"serialNumber": ["12345"]}
- raises(MissingValue, filter_on_attributes, ava, required, acs=ac_factory())
+ with raises(MissingValue):
+ filter_on_attributes(ava, required, acs=ac_factory())
def test_filter_values_req_5():
@@ -564,7 +564,8 @@ def test_filter_values_req_opt_2():
ava = {"surname": ["Hedberg"], "givenName": ["Roland"],
"eduPersonAffiliation": ["staff"], "uid": ["rohe0002"]}
- raises(MissingValue, "filter_on_attributes(ava, r, o, acs=ac_factory())")
+ with raises(MissingValue):
+ filter_on_attributes(ava, r, o, acs=ac_factory())
# ---------------------------------------------------------------------------
diff --git a/tests/test_31_config.py b/tests/test_31_config.py
index 189d3109..407e46e2 100644
--- a/tests/test_31_config.py
+++ b/tests/test_31_config.py
@@ -7,7 +7,6 @@ from saml2.mdstore import MetadataStore, name
from saml2 import BINDING_HTTP_REDIRECT, BINDING_SOAP, BINDING_HTTP_POST
from saml2.config import SPConfig, IdPConfig, Config
-from py.test import raises
from saml2 import root_logger
diff --git a/tests/test_32_cache.py b/tests/test_32_cache.py
index 97442d87..1dc1b4eb 100644
--- a/tests/test_32_cache.py
+++ b/tests/test_32_cache.py
@@ -1,12 +1,15 @@
#!/usr/bin/env python
import time
-import py
+
+from pytest import raises
+
from saml2.saml import NameID, NAMEID_FORMAT_TRANSIENT
from saml2.cache import Cache
from saml2.time_util import in_a_while, str_to_time
from saml2.ident import code
+
SESSION_INFO_PATTERN = {"ava": {}, "came from": "", "not_on_or_after": 0,
"issuer": "", "session_id": -1}
@@ -64,7 +67,8 @@ class TestClass:
def test_entities(self):
assert _eq(self.cache.entities(nid[0]), ["abcd", "bcde"])
- py.test.raises(Exception, "self.cache.entities('6666')")
+ with raises(Exception):
+ self.cache.entities('6666')
def test_remove_info(self):
self.cache.reset(nid[0], "bcde")
diff --git a/tests/test_36_mdbcache.py b/tests/test_36_mdbcache.py
index 66826f12..07808d82 100644
--- a/tests/test_36_mdbcache.py
+++ b/tests/test_36_mdbcache.py
@@ -9,8 +9,15 @@ from saml2.mdbcache import Cache
from saml2.time_util import in_a_while, str_to_time
from pytest import raises
-SESSION_INFO_PATTERN = {"ava":{}, "came from":"", "not_on_or_after":0,
- "issuer":"", "session_id":-1}
+
+SESSION_INFO_PATTERN = {
+ "ava": {},
+ "came from": "",
+ "not_on_or_after": 0,
+ "issuer": "",
+ "session_id": -1
+}
+
@pytest.mark.mongo
class TestMongoDBCache():
@@ -46,7 +53,9 @@ class TestMongoDBCache():
not_on_or_after)
time.sleep(2)
- raises(ToOld, 'self.cache.get("1235", "abcd")')
+ with raises(ToOld):
+ self.cache.get("1235", "abcd")
+
info = self.cache.get("1235", "abcd", False)
assert info != {}
diff --git a/tests/test_40_sigver.py b/tests/test_40_sigver.py
index 092fbc67..b7566297 100644
--- a/tests/test_40_sigver.py
+++ b/tests/test_40_sigver.py
@@ -20,7 +20,7 @@ from saml2.samlp import response_from_string
from saml2.s_utils import factory, do_attribute_statement
import pytest
-from py.test import raises
+from pytest import raises
from pathutils import full_path
@@ -424,8 +424,8 @@ class TestSecurity():
response2 = response_from_string(s_response)
# Change something that should make everything fail
response2.id = "23456"
- raises(sigver.SignatureError, self.sec._check_signature,
- s_response, response2, class_name(response2))
+ with raises(sigver.SignatureError):
+ self.sec._check_signature(s_response, response2, class_name(response2))
class TestSecurityNonAsciiAva():
@@ -719,8 +719,8 @@ class TestSecurityNonAsciiAva():
response2 = response_from_string(s_response)
# Change something that should make everything fail
response2.id = "23456"
- raises(sigver.SignatureError, self.sec._check_signature,
- s_response, response2, class_name(response2))
+ with raises(sigver.SignatureError):
+ self.sec._check_signature(s_response, response2, class_name(response2))
class TestSecurityMetadata():
@@ -1026,13 +1026,15 @@ def test_xmlsec_output_line_parsing():
assert sigver.parse_xmlsec_output(output1)
output2 = "prefix\nFAIL\npostfix"
- raises(sigver.XmlsecError, sigver.parse_xmlsec_output, output2)
+ with raises(sigver.XmlsecError):
+ sigver.parse_xmlsec_output(output2)
output3 = "prefix\r\nOK\r\npostfix"
assert sigver.parse_xmlsec_output(output3)
output4 = "prefix\r\nFAIL\r\npostfix"
- raises(sigver.XmlsecError, sigver.parse_xmlsec_output, output4)
+ with raises(sigver.XmlsecError):
+ sigver.parse_xmlsec_output(output4)
if __name__ == "__main__":
diff --git a/tests/test_50_server.py b/tests/test_50_server.py
index ecef319e..3d828171 100644
--- a/tests/test_50_server.py
+++ b/tests/test_50_server.py
@@ -30,7 +30,7 @@ from saml2.soap import make_soap_enveloped_saml_thingy
from saml2 import BINDING_HTTP_POST
from saml2 import BINDING_HTTP_REDIRECT
-from py.test import raises
+from pytest import raises
from pathutils import full_path
import saml2.xmldsig as ds
@@ -220,8 +220,8 @@ class TestServer1():
binding, "%s" % authn_request, "http://www.example.com", "abcd")
_dict = parse_qs(htargs["headers"][0][1].split('?')[1])
print(_dict)
- raises(OtherError, self.server.parse_authn_request,
- _dict["SAMLRequest"][0], binding)
+ with raises(OtherError):
+ self.server.parse_authn_request(_dict["SAMLRequest"][0], binding)
def test_parse_faulty_request_to_err_status(self):
req_id, authn_request = self.client.create_authn_request(
@@ -1294,8 +1294,8 @@ class TestServer1NonAsciiAva():
binding, "%s" % authn_request, "http://www.example.com", "abcd")
_dict = parse_qs(htargs["headers"][0][1].split('?')[1])
print(_dict)
- raises(OtherError, self.server.parse_authn_request,
- _dict["SAMLRequest"][0], binding)
+ with raises(OtherError):
+ self.server.parse_authn_request(_dict["SAMLRequest"][0], binding)
def test_parse_faulty_request_to_err_status(self):
req_id, authn_request = self.client.create_authn_request(
diff --git a/tests/test_51_client.py b/tests/test_51_client.py
index f24fb709..a063dcb4 100644
--- a/tests/test_51_client.py
+++ b/tests/test_51_client.py
@@ -1552,10 +1552,12 @@ class TestClient:
response = create_authn_response(**kwargs)
set_client_want(True, True, True)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(True, True, False)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(True, False, True)
parse_authn_response(response)
@@ -1564,10 +1566,12 @@ class TestClient:
parse_authn_response(response)
set_client_want(False, True, True)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(False, True, False)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(False, False, True)
parse_authn_response(response)
@@ -1581,16 +1585,20 @@ class TestClient:
response = create_authn_response(**kwargs)
set_client_want(True, True, True)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(True, True, False)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(True, False, True)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(True, False, False)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(False, True, True)
parse_authn_response(response)
@@ -1639,25 +1647,32 @@ class TestClient:
response = create_authn_response(**kwargs)
set_client_want(True, True, True)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(True, True, False)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(True, False, True)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(True, False, False)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(False, True, True)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(False, True, False)
- raises(SignatureError, parse_authn_response, response)
+ with raises(SignatureError):
+ parse_authn_response(response)
set_client_want(False, False, True)
- raises(SigverError, parse_authn_response, response)
+ with raises(SigverError):
+ parse_authn_response(response)
set_client_want(False, False, False)
parse_authn_response(response)