Skip to content

Commit 124376b

Browse files
committed
Fix tests to be compatible with latest pytest
Signed-off-by: Ivan Kanakarakis <[email protected]>
1 parent 5a43595 commit 124376b

11 files changed

+100
-64
lines changed

tests/test_02_saml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from saml2 import saml
2121

22-
from py.test import raises
22+
from pytest import raises
2323

2424
from saml2.saml import Issuer
2525
from saml2.saml import Attribute

tests/test_03_saml2.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from saml2.saml import SubjectConfirmationData, SubjectConfirmation
88
from saml2.saml import Attribute
99

10-
from py.test import raises
10+
from pytest import raises
1111
import saml2_data
1212

1313
try:
@@ -28,7 +28,7 @@
2828
</NameID>
2929
""", """<?xml version="1.0" encoding="utf-8"?>
3030
<NameID xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
31-
SPNameQualifier="https://foo.example.com/sp"
31+
SPNameQualifier="https://foo.example.com/sp"
3232
Format="urn:oasis:names:tc:SAML:2.0:nameid-format:transient">_1632879f09d08ea5ede2dc667cbed7e429ebc4335c</NameID>
3333
""", """<?xml version="1.0" encoding="utf-8"?>
3434
<NameID xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
@@ -48,9 +48,9 @@
4848
SubjectConfirmationData:
4949
"""<?xml version="1.0" encoding="utf-8"?>
5050
<SubjectConfirmationData xmlns="urn:oasis:names:tc:SAML:2.0:assertion"
51-
InResponseTo="_1683146e27983964fbe7bf8f08961108d166a652e5"
52-
NotOnOrAfter="2010-02-18T13:52:13.959Z"
53-
NotBefore="2010-01-16T12:00:00Z"
51+
InResponseTo="_1683146e27983964fbe7bf8f08961108d166a652e5"
52+
NotOnOrAfter="2010-02-18T13:52:13.959Z"
53+
NotBefore="2010-01-16T12:00:00Z"
5454
Recipient="http://192.168.0.10/saml/sp" />""",
5555
SubjectConfirmation:
5656
"""<?xml version="1.0" encoding="utf-8"?>
@@ -176,7 +176,7 @@ def test_create_class_from_xml_string_xxe():
176176
]>
177177
<lolz>&lol1;</lolz>
178178
"""
179-
with raises(EntitiesForbidden) as err:
179+
with raises(EntitiesForbidden):
180180
create_class_from_xml_string(NameID, xml)
181181

182182

@@ -207,7 +207,7 @@ def test_ee_2():
207207
def test_ee_3():
208208
ee = saml2.extension_element_from_string(
209209
"""<?xml version='1.0' encoding='UTF-8'?>
210-
<foo xmlns="urn:mace:example.com:saml:ns"
210+
<foo xmlns="urn:mace:example.com:saml:ns"
211211
id="xyz">bar</foo>""")
212212
assert ee != None
213213
print(ee.__dict__)

tests/test_12_s_utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
from saml2.saml import Attribute, Subject
1515
from saml2.saml import NAME_FORMAT_URI
1616

17-
from py.test import raises
18-
1917
from pathutils import full_path
2018

19+
2120
XML_HEADER = '<?xml version=\'1.0\' encoding=\'UTF-8\'?>\n'
2221

2322
SUCCESS_STATUS_NO_HEADER = (
@@ -64,7 +63,7 @@ def _oeq(l1, l2):
6463

6564
def test_inflate_then_deflate():
6665
txt = """Selma Lagerlöf (1858-1940) was born in Östra Emterwik, Värmland,
67-
Sweden. She was brought up on Mårbacka, the family estate, which she did
66+
Sweden. She was brought up on Mårbacka, the family estate, which she did
6867
not leave until 1881, when she went to a teachers' college at Stockholm"""
6968
if not isinstance(txt, six.binary_type):
7069
txt = txt.encode('utf-8')

tests/test_13_validate.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from saml2.validate import NotValid
1515
from saml2.validate import valid_anytype
1616

17-
from py.test import raises
17+
from pytest import raises
1818

1919

2020
def _eq(l1, l2):
@@ -33,23 +33,30 @@ def test_duration():
3333
assert valid_duration("-P1347M")
3434
assert valid_duration("P1Y2MT2.5H")
3535

36-
raises(NotValid, 'valid_duration("P-1347M")')
37-
raises(NotValid, ' valid_duration("P1Y2MT")')
38-
raises(NotValid, ' valid_duration("P1Y2MT2xH")')
36+
with raises(NotValid):
37+
valid_duration("P-1347M")
38+
with raises(NotValid):
39+
valid_duration("P1Y2MT")
40+
with raises(NotValid):
41+
valid_duration("P1Y2MT2xH")
3942

4043

4144
def test_unsigned_short():
4245
assert valid_unsigned_short("1234")
4346

44-
raises(NotValid, ' valid_unsigned_short("-1234")')
45-
raises(NotValid, ' valid_unsigned_short("1234567890")')
47+
with raises(NotValid):
48+
valid_unsigned_short("-1234")
49+
with raises(NotValid):
50+
valid_unsigned_short("1234567890")
4651

4752

4853
def test_valid_non_negative_integer():
4954
assert valid_non_negative_integer("1234567890")
5055

51-
raises(NotValid, 'valid_non_negative_integer("-123")')
52-
raises(NotValid, 'valid_non_negative_integer("123.56")')
56+
with raises(NotValid):
57+
valid_non_negative_integer("-123")
58+
with raises(NotValid):
59+
valid_non_negative_integer("123.56")
5360
assert valid_non_negative_integer("12345678901234567890")
5461

5562

@@ -58,9 +65,8 @@ def test_valid_string():
5865

5966
import codecs
6067

61-
raises(NotValid,
62-
'valid_string(codecs.getdecoder("hex_codec")'
63-
'(b"02656c6c6f")[0].decode("utf-8"))')
68+
with raises(NotValid):
69+
valid_string(codecs.getdecoder("hex_codec")(b"02656c6c6f")[0].decode("utf-8"))
6470

6571

6672
def test_valid_anyuri():
@@ -102,7 +108,8 @@ def test_valid_instance():
102108
response.status = samlp.Status()
103109
response.assertion.append(saml.Assertion())
104110

105-
raises(MustValueError, 'valid_instance(response)')
111+
with raises(MustValueError):
112+
valid_instance(response)
106113

107114

108115
def test_valid_anytype():

tests/test_20_assertion.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
# coding=utf-8
2-
import pytest
3-
42
from saml2.argtree import add_path
53
from saml2.authn_context import pword
64
from saml2.mdie import to_dict
@@ -21,7 +19,7 @@
2119
from saml2 import attribute_converter
2220
from saml2.attribute_converter import ac_factory, AttributeConverterNOOP
2321

24-
from py.test import raises
22+
from pytest import raises
2523

2624
from saml2.extension import mdui
2725
from saml2.extension import idpdisc
@@ -82,7 +80,7 @@ def test_filter_on_attributes_1():
8280

8381

8482
def test_filter_on_attributes_2():
85-
83+
8684
a = to_dict(Attribute(friendly_name="surName",name="urn:oid:2.5.4.4",
8785
name_format=NAME_FORMAT_URI), ONTS)
8886
required = [a]
@@ -117,7 +115,7 @@ def test_filter_on_attributes_with_missing_required_attribute():
117115
friendly_name="eduPersonTargetedID",
118116
name="urn:oid:1.3.6.1.4.1.5923.1.1.1.10",
119117
name_format=NAME_FORMAT_URI), ONTS)
120-
with pytest.raises(MissingValue):
118+
with raises(MissingValue):
121119
filter_on_attributes(ava, required=[eptid], acs=ac_factory())
122120

123121

@@ -441,7 +439,8 @@ def test_filter_values_req_2():
441439
required = [a1, a2]
442440
ava = {"serialNumber": ["12345"], "givenName": ["Lars"]}
443441

444-
raises(MissingValue, filter_on_attributes, ava, required, acs=ac_factory())
442+
with raises(MissingValue):
443+
filter_on_attributes(ava, required, acs=ac_factory())
445444

446445

447446
def test_filter_values_req_3():
@@ -467,7 +466,8 @@ def test_filter_values_req_4():
467466
required = [a]
468467
ava = {"serialNumber": ["12345"]}
469468

470-
raises(MissingValue, filter_on_attributes, ava, required, acs=ac_factory())
469+
with raises(MissingValue):
470+
filter_on_attributes(ava, required, acs=ac_factory())
471471

472472

473473
def test_filter_values_req_5():
@@ -564,7 +564,8 @@ def test_filter_values_req_opt_2():
564564
ava = {"surname": ["Hedberg"], "givenName": ["Roland"],
565565
"eduPersonAffiliation": ["staff"], "uid": ["rohe0002"]}
566566

567-
raises(MissingValue, "filter_on_attributes(ava, r, o, acs=ac_factory())")
567+
with raises(MissingValue):
568+
filter_on_attributes(ava, r, o, acs=ac_factory())
568569

569570

570571
# ---------------------------------------------------------------------------

tests/test_31_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from saml2 import BINDING_HTTP_REDIRECT, BINDING_SOAP, BINDING_HTTP_POST
99
from saml2.config import SPConfig, IdPConfig, Config
10-
from py.test import raises
1110

1211
from saml2 import root_logger
1312

tests/test_32_cache.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
#!/usr/bin/env python
22

33
import time
4-
import py
4+
5+
from pytest import raises
6+
57
from saml2.saml import NameID, NAMEID_FORMAT_TRANSIENT
68
from saml2.cache import Cache
79
from saml2.time_util import in_a_while, str_to_time
810
from saml2.ident import code
911

12+
1013
SESSION_INFO_PATTERN = {"ava": {}, "came from": "", "not_on_or_after": 0,
1114
"issuer": "", "session_id": -1}
1215

@@ -64,7 +67,8 @@ def test_from_one_target_source(self):
6467

6568
def test_entities(self):
6669
assert _eq(self.cache.entities(nid[0]), ["abcd", "bcde"])
67-
py.test.raises(Exception, "self.cache.entities('6666')")
70+
with raises(Exception):
71+
self.cache.entities('6666')
6872

6973
def test_remove_info(self):
7074
self.cache.reset(nid[0], "bcde")

tests/test_36_mdbcache.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,15 @@
99
from saml2.time_util import in_a_while, str_to_time
1010
from pytest import raises
1111

12-
SESSION_INFO_PATTERN = {"ava":{}, "came from":"", "not_on_or_after":0,
13-
"issuer":"", "session_id":-1}
12+
13+
SESSION_INFO_PATTERN = {
14+
"ava": {},
15+
"came from": "",
16+
"not_on_or_after": 0,
17+
"issuer": "",
18+
"session_id": -1
19+
}
20+
1421

1522
@pytest.mark.mongo
1623
class TestMongoDBCache():
@@ -46,7 +53,9 @@ def test_set_get_2(self):
4653
not_on_or_after)
4754
time.sleep(2)
4855

49-
raises(ToOld, 'self.cache.get("1235", "abcd")')
56+
with raises(ToOld):
57+
self.cache.get("1235", "abcd")
58+
5059
info = self.cache.get("1235", "abcd", False)
5160
assert info != {}
5261

tests/test_40_sigver.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from saml2.s_utils import factory, do_attribute_statement
2121

2222
import pytest
23-
from py.test import raises
23+
from pytest import raises
2424

2525
from pathutils import full_path
2626

@@ -424,8 +424,8 @@ def test_exception_sign_verify_with_cert_from_instance(self):
424424
response2 = response_from_string(s_response)
425425
# Change something that should make everything fail
426426
response2.id = "23456"
427-
raises(sigver.SignatureError, self.sec._check_signature,
428-
s_response, response2, class_name(response2))
427+
with raises(sigver.SignatureError):
428+
self.sec._check_signature(s_response, response2, class_name(response2))
429429

430430

431431
class TestSecurityNonAsciiAva():
@@ -719,8 +719,8 @@ def test_exception_sign_verify_with_cert_from_instance(self):
719719
response2 = response_from_string(s_response)
720720
# Change something that should make everything fail
721721
response2.id = "23456"
722-
raises(sigver.SignatureError, self.sec._check_signature,
723-
s_response, response2, class_name(response2))
722+
with raises(sigver.SignatureError):
723+
self.sec._check_signature(s_response, response2, class_name(response2))
724724

725725

726726
class TestSecurityMetadata():
@@ -1026,13 +1026,15 @@ def test_xmlsec_output_line_parsing():
10261026
assert sigver.parse_xmlsec_output(output1)
10271027

10281028
output2 = "prefix\nFAIL\npostfix"
1029-
raises(sigver.XmlsecError, sigver.parse_xmlsec_output, output2)
1029+
with raises(sigver.XmlsecError):
1030+
sigver.parse_xmlsec_output(output2)
10301031

10311032
output3 = "prefix\r\nOK\r\npostfix"
10321033
assert sigver.parse_xmlsec_output(output3)
10331034

10341035
output4 = "prefix\r\nFAIL\r\npostfix"
1035-
raises(sigver.XmlsecError, sigver.parse_xmlsec_output, output4)
1036+
with raises(sigver.XmlsecError):
1037+
sigver.parse_xmlsec_output(output4)
10361038

10371039

10381040
if __name__ == "__main__":

tests/test_50_server.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from saml2 import BINDING_HTTP_POST
3131
from saml2 import BINDING_HTTP_REDIRECT
3232

33-
from py.test import raises
33+
from pytest import raises
3434
from pathutils import full_path
3535
import saml2.xmldsig as ds
3636

@@ -220,8 +220,8 @@ def test_parse_faulty_request(self):
220220
binding, "%s" % authn_request, "http://www.example.com", "abcd")
221221
_dict = parse_qs(htargs["headers"][0][1].split('?')[1])
222222
print(_dict)
223-
raises(OtherError, self.server.parse_authn_request,
224-
_dict["SAMLRequest"][0], binding)
223+
with raises(OtherError):
224+
self.server.parse_authn_request(_dict["SAMLRequest"][0], binding)
225225

226226
def test_parse_faulty_request_to_err_status(self):
227227
req_id, authn_request = self.client.create_authn_request(
@@ -1294,8 +1294,8 @@ def test_parse_faulty_request(self):
12941294
binding, "%s" % authn_request, "http://www.example.com", "abcd")
12951295
_dict = parse_qs(htargs["headers"][0][1].split('?')[1])
12961296
print(_dict)
1297-
raises(OtherError, self.server.parse_authn_request,
1298-
_dict["SAMLRequest"][0], binding)
1297+
with raises(OtherError):
1298+
self.server.parse_authn_request(_dict["SAMLRequest"][0], binding)
12991299

13001300
def test_parse_faulty_request_to_err_status(self):
13011301
req_id, authn_request = self.client.create_authn_request(

0 commit comments

Comments
 (0)