Skip to content

Commit 13d6348

Browse files
author
Roland Hedberg
committed
Fixed tests
1 parent 69c5e07 commit 13d6348

File tree

3 files changed

+67
-25
lines changed

3 files changed

+67
-25
lines changed

tests/test_10_time_util.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,33 @@ def test_parse_duration2():
6666
assert d['tm_min'] == 30
6767

6868

69+
PATTERNS = {
70+
"P3Y6M4DT12H30M5S": {'tm_sec': 5, 'tm_hour': 12, 'tm_mday': 4,
71+
'tm_year': 3, 'tm_mon': 6, 'tm_min': 30},
72+
"P23DT23H": {'tm_sec': 0, 'tm_hour': 23, 'tm_mday': 23, 'tm_year': 0,
73+
'tm_mon': 0, 'tm_min': 0},
74+
"P4Y": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 4,
75+
'tm_mon': 0, 'tm_min': 0},
76+
"P1M": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 0,
77+
'tm_mon': 1, 'tm_min': 0},
78+
"PT1M": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 0,
79+
'tm_mon': 0, 'tm_min': 1},
80+
"P0.5Y": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 0.5,
81+
'tm_mon': 0, 'tm_min': 0},
82+
"P0,5Y": {'tm_sec': 0, 'tm_hour': 0, 'tm_mday': 0, 'tm_year': 0.5,
83+
'tm_mon': 0, 'tm_min': 0},
84+
"PT36H": {'tm_sec': 0, 'tm_hour': 36, 'tm_mday': 0, 'tm_year': 0,
85+
'tm_mon': 0, 'tm_min': 0},
86+
"P1DT12H": {'tm_sec': 0, 'tm_hour': 12, 'tm_mday': 1, 'tm_year': 0,
87+
'tm_mon': 0, 'tm_min': 0}
88+
}
89+
90+
91+
def test_parse_duration_n():
92+
for dur, _val in PATTERNS.items():
93+
(sign, d) = parse_duration(dur)
94+
assert d == _val
95+
6996
def test_add_duration_1():
7097
#2000-01-12T12:13:14Z P1Y3M5DT7H10M3S 2001-04-17T19:23:17Z
7198
t = add_duration(str_to_time("2000-01-12T12:13:14Z"), "P1Y3M5DT7H10M3S")
@@ -145,5 +172,6 @@ def test_not_on_or_after():
145172
assert not_on_or_after("%d-01-01T00:00:00Z" % (current_year + 1)) == True
146173
assert not_on_or_after("%d-01-01T00:00:00Z" % (current_year - 1)) == False
147174

175+
148176
if __name__ == "__main__":
149-
test_parse_duration2()
177+
test_parse_duration_n()

tests/test_13_validate.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818

1919
from py.test import raises
2020

21-
def _eq(l1,l2):
21+
22+
def _eq(l1, l2):
2223
return set(l1) == set(l2)
2324

25+
2426
def test_duration():
2527
assert valid_duration("P1Y2M3DT10H30M")
2628
assert valid_duration("P1Y2M3DT10H30M1.567S")
@@ -31,41 +33,45 @@ def test_duration():
3133
assert valid_duration("P0Y1347M")
3234
assert valid_duration("P0Y1347M0D")
3335
assert valid_duration("-P1347M")
36+
assert valid_duration("P1Y2MT2.5H")
37+
38+
raises(NotValid, 'valid_duration("P-1347M")')
39+
raises(NotValid, ' valid_duration("P1Y2MT")')
40+
raises(NotValid, ' valid_duration("P1Y2MT2xH")')
3441

35-
raises( NotValid, 'valid_duration("P-1347M")')
36-
raises( NotValid, ' valid_duration("P1Y2MT")')
37-
raises( NotValid, ' valid_duration("P1Y2MT2.5H")')
38-
raises( NotValid, ' valid_duration("P1Y2MT2xH")')
39-
4042

4143
def test_unsigned_short():
4244
assert valid_unsigned_short("1234")
43-
44-
raises( NotValid, ' valid_unsigned_short("-1234")')
45-
raises( NotValid, ' valid_unsigned_short("1234567890")')
45+
46+
raises(NotValid, ' valid_unsigned_short("-1234")')
47+
raises(NotValid, ' valid_unsigned_short("1234567890")')
48+
4649

4750
def test_valid_non_negative_integer():
4851
assert valid_non_negative_integer("1234567890")
49-
50-
raises( NotValid, 'valid_non_negative_integer("-123")')
51-
raises( NotValid, 'valid_non_negative_integer("123.56")')
52+
53+
raises(NotValid, 'valid_non_negative_integer("-123")')
54+
raises(NotValid, 'valid_non_negative_integer("123.56")')
5255
assert valid_non_negative_integer("12345678901234567890")
5356

57+
5458
def test_valid_string():
5559
assert valid_string(u'example')
56-
57-
raises( NotValid, 'valid_string("02656c6c6f".decode("hex"))')
58-
60+
61+
raises(NotValid, 'valid_string("02656c6c6f".decode("hex"))')
62+
63+
5964
def test_valid_anyuri():
6065
assert valid_any_uri("urn:oasis:names:tc:SAML:2.0:attrname-format:uri")
61-
66+
67+
6268
def test_valid_instance():
6369
attr_statem = saml.AttributeStatement()
6470
text = ["value of test attribute",
6571
"value1 of test attribute",
6672
"value2 of test attribute",
6773
"value1 of test attribute2",
68-
"value2 of test attribute2",]
74+
"value2 of test attribute2", ]
6975

7076
attr_statem.attribute.append(saml.Attribute())
7177
attr_statem.attribute.append(saml.Attribute())
@@ -80,9 +86,9 @@ def test_valid_instance():
8086
attr_statem.attribute[1].friendly_name = text[2]
8187
attr_statem.attribute[1].attribute_value.append(saml.AttributeValue())
8288
attr_statem.attribute[1].attribute_value[0].text = text[2]
83-
89+
8490
assert valid_instance(attr_statem)
85-
91+
8692
response = samlp.Response()
8793
response.id = "response id"
8894
response.in_response_to = "request id"
@@ -94,8 +100,9 @@ def test_valid_instance():
94100
response.status = samlp.Status()
95101
response.assertion.append(saml.Assertion())
96102

97-
raises( MustValueError, 'valid_instance(response)')
98-
103+
raises(MustValueError, 'valid_instance(response)')
104+
105+
99106
def test_valid_anytype():
100107
assert valid_anytype("130.239.16.3")
101108
assert valid_anytype("textstring")

tests/test_67_manage_name_id.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
__author__ = 'rolandh'
88

9+
910
def test_basic():
1011
sp = Saml2Client(config_file="servera_conf")
1112
idp = Server(config_file="idp_all_conf")
@@ -18,7 +19,7 @@ def test_basic():
1819
newid = NewID(text="Barfoo")
1920

2021
mid, mreq = sp.create_manage_name_id_request(destination, name_id=nameid,
21-
new_id=newid)
22+
new_id=newid)
2223

2324
print mreq
2425
rargs = sp.apply_binding(binding, "%s" % mreq, destination, "")
@@ -31,6 +32,7 @@ def test_basic():
3132

3233
assert mid == _req.message.id
3334

35+
3436
def test_flow():
3537
sp = Saml2Client(config_file="servera_conf")
3638
idp = Server(config_file="idp_all_conf")
@@ -42,7 +44,7 @@ def test_flow():
4244
newid = NewID(text="Barfoo")
4345

4446
mid, midq = sp.create_manage_name_id_request(destination, name_id=nameid,
45-
new_id=newid)
47+
new_id=newid)
4648

4749
print midq
4850
rargs = sp.apply_binding(binding, "%s" % midq, destination, "")
@@ -67,8 +69,13 @@ def test_flow():
6769

6870
# ---------- @SP ---------------
6971

70-
_response = sp.parse_manage_name_id_request_response(respargs["data"], binding)
72+
_response = sp.parse_manage_name_id_request_response(respargs["data"],
73+
binding)
7174

7275
print _response.response
7376

7477
assert _response.response.id == mnir.id
78+
79+
80+
if __name__ == "__main__":
81+
test_flow()

0 commit comments

Comments
 (0)