Fixed tests

This commit is contained in:
Roland Hedberg
2014-04-08 17:38:07 +02:00
parent 69c5e078e0
commit 13d63480c9
3 changed files with 67 additions and 25 deletions

View File

@@ -66,6 +66,33 @@ def test_parse_duration2():
assert d['tm_min'] == 30
PATTERNS = {
"P3Y6M4DT12H30M5S": {'tm_sec': 5, 'tm_hour': 12, 'tm_mday': 4,
'tm_year': 3, 'tm_mon': 6, 'tm_min': 30},
"P23DT23H": {'tm_sec': 0, 'tm_hour': 23, 'tm_mday': 23, 'tm_year': 0,
'tm_mon': 0, 'tm_min': 0},
"P4Y": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 4,
'tm_mon': 0, 'tm_min': 0},
"P1M": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 0,
'tm_mon': 1, 'tm_min': 0},
"PT1M": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 0,
'tm_mon': 0, 'tm_min': 1},
"P0.5Y": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 0.5,
'tm_mon': 0, 'tm_min': 0},
"P0,5Y": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 0.5,
'tm_mon': 0, 'tm_min': 0},
"PT36H": {'tm_sec': 0, 'tm_hour': 36, 'tm_mday': 0, 'tm_year': 0,
'tm_mon': 0, 'tm_min': 0},
"P1DT12H": {'tm_sec': 0, 'tm_hour': 12, 'tm_mday': 1, 'tm_year': 0,
'tm_mon': 0, 'tm_min': 0}
}
def test_parse_duration_n():
for dur, _val in PATTERNS.items():
(sign, d) = parse_duration(dur)
assert d == _val
def test_add_duration_1():
#2000-01-12T12:13:14Z P1Y3M5DT7H10M3S 2001-04-17T19:23:17Z
t = add_duration(str_to_time("2000-01-12T12:13:14Z"), "P1Y3M5DT7H10M3S")
@@ -145,5 +172,6 @@ def test_not_on_or_after():
assert not_on_or_after("%d-01-01T00:00:00Z" % (current_year + 1)) == True
assert not_on_or_after("%d-01-01T00:00:00Z" % (current_year - 1)) == False
if __name__ == "__main__":
test_parse_duration2()
test_parse_duration_n()

View File

@@ -18,9 +18,11 @@ from saml2.validate import valid_anytype
from py.test import raises
def _eq(l1,l2):
def _eq(l1, l2):
return set(l1) == set(l2)
def test_duration():
assert valid_duration("P1Y2M3DT10H30M")
assert valid_duration("P1Y2M3DT10H30M1.567S")
@@ -31,41 +33,45 @@ def test_duration():
assert valid_duration("P0Y1347M")
assert valid_duration("P0Y1347M0D")
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")')
raises( NotValid, 'valid_duration("P-1347M")')
raises( NotValid, ' valid_duration("P1Y2MT")')
raises( NotValid, ' valid_duration("P1Y2MT2.5H")')
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")')
raises(NotValid, ' valid_unsigned_short("-1234")')
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")')
raises(NotValid, 'valid_non_negative_integer("-123")')
raises(NotValid, 'valid_non_negative_integer("123.56")')
assert valid_non_negative_integer("12345678901234567890")
def test_valid_string():
assert valid_string(u'example')
raises( NotValid, 'valid_string("02656c6c6f".decode("hex"))')
raises(NotValid, 'valid_string("02656c6c6f".decode("hex"))')
def test_valid_anyuri():
assert valid_any_uri("urn:oasis:names:tc:SAML:2.0:attrname-format:uri")
def test_valid_instance():
attr_statem = saml.AttributeStatement()
text = ["value of test attribute",
"value1 of test attribute",
"value2 of test attribute",
"value1 of test attribute2",
"value2 of test attribute2",]
"value2 of test attribute2", ]
attr_statem.attribute.append(saml.Attribute())
attr_statem.attribute.append(saml.Attribute())
@@ -80,9 +86,9 @@ def test_valid_instance():
attr_statem.attribute[1].friendly_name = text[2]
attr_statem.attribute[1].attribute_value.append(saml.AttributeValue())
attr_statem.attribute[1].attribute_value[0].text = text[2]
assert valid_instance(attr_statem)
response = samlp.Response()
response.id = "response id"
response.in_response_to = "request id"
@@ -94,8 +100,9 @@ def test_valid_instance():
response.status = samlp.Status()
response.assertion.append(saml.Assertion())
raises( MustValueError, 'valid_instance(response)')
raises(MustValueError, 'valid_instance(response)')
def test_valid_anytype():
assert valid_anytype("130.239.16.3")
assert valid_anytype("textstring")

View File

@@ -6,6 +6,7 @@ from saml2.server import Server
__author__ = 'rolandh'
def test_basic():
sp = Saml2Client(config_file="servera_conf")
idp = Server(config_file="idp_all_conf")
@@ -18,7 +19,7 @@ def test_basic():
newid = NewID(text="Barfoo")
mid, mreq = sp.create_manage_name_id_request(destination, name_id=nameid,
new_id=newid)
new_id=newid)
print mreq
rargs = sp.apply_binding(binding, "%s" % mreq, destination, "")
@@ -31,6 +32,7 @@ def test_basic():
assert mid == _req.message.id
def test_flow():
sp = Saml2Client(config_file="servera_conf")
idp = Server(config_file="idp_all_conf")
@@ -42,7 +44,7 @@ def test_flow():
newid = NewID(text="Barfoo")
mid, midq = sp.create_manage_name_id_request(destination, name_id=nameid,
new_id=newid)
new_id=newid)
print midq
rargs = sp.apply_binding(binding, "%s" % midq, destination, "")
@@ -67,8 +69,13 @@ def test_flow():
# ---------- @SP ---------------
_response = sp.parse_manage_name_id_request_response(respargs["data"], binding)
_response = sp.parse_manage_name_id_request_response(respargs["data"],
binding)
print _response.response
assert _response.response.id == mnir.id
if __name__ == "__main__":
test_flow()