Skip to content

Commit fc42b2a

Browse files
Merge pull request #748 from brunato/fix-identifier-tests
Fix test_33_identifier.py to avoid reuse of old test data files
2 parents 07db486 + 4f60e0d commit fc42b2a

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ example/*/modules/
77

88
tests/*.log.*
99
tests/*.db
10+
tests/*.dir
11+
tests/*.dat
12+
tests/*.bak
13+
1014

1115
eptid
1216

@@ -117,6 +121,9 @@ venv.bak/
117121
# Visual Studio Code files
118122
.vscode/
119123

124+
# PyCharm project files
125+
.idea/
126+
120127
# mkdocs documentation
121128
/site
122129

tests/test_33_identifier.py

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,39 @@
77
from saml2.ident import IdentDB
88
from saml2.assertion import Policy
99

10-
def _eq(l1,l2):
10+
from pathutils import full_path
11+
12+
13+
def _eq(l1, l2):
1114
return set(l1) == set(l2)
1215

16+
1317
CONFIG = IdPConfig().load({
14-
"entityid" : "urn:mace:example.com:idp:2",
15-
"name" : "test",
18+
"entityid": "urn:mace:example.com:idp:2",
19+
"name": "test",
1620
"service": {
1721
"idp": {
18-
"endpoints" : {
19-
"single_sign_on_service" : ["http://idp.example.org/"],
20-
},
22+
"endpoints": {
23+
"single_sign_on_service": ["http://idp.example.org/"],
24+
},
2125
"policy": {
2226
"default": {
23-
"lifetime": {"minutes":15},
24-
"attribute_restrictions": None, # means all I have
25-
"name_form": "urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
27+
"lifetime": {"minutes": 15},
28+
"attribute_restrictions": None, # means all I have
29+
"name_form":
30+
"urn:oasis:names:tc:SAML:2.0:attrname-format:uri",
2631
"nameid_format": NAMEID_FORMAT_PERSISTENT
2732
}
2833
}
2934
}
3035
},
31-
"virtual_organization" : {
32-
"http://vo.example.org/biomed":{
33-
"nameid_format" : "urn:oid:2.16.756.1.2.5.1.1.1-NameID",
36+
"virtual_organization": {
37+
"http://vo.example.org/biomed": {
38+
"nameid_format": "urn:oid:2.16.756.1.2.5.1.1.1-NameID",
3439
"common_identifier": "uid",
3540
},
36-
"http://vo.example.org/design":{
37-
"nameid_format" : NAMEID_FORMAT_PERSISTENT,
41+
"http://vo.example.org/design": {
42+
"nameid_format": NAMEID_FORMAT_PERSISTENT,
3843
"common_identifier": "uid",
3944
}
4045
}
@@ -53,13 +58,14 @@ def _eq(l1,l2):
5358
"""
5459

5560

56-
class TestIdentifier():
61+
class TestIdentifier:
5762
def setup_class(self):
58-
try:
59-
os.remove("subject.db.db")
60-
except:
61-
pass
62-
self.id = IdentDB("subject.db", "example.com", "example")
63+
for extension in ('.db', '.dir', '.dat', '.bak'):
64+
try:
65+
os.remove(full_path("subject.db{}".format(extension)))
66+
except (OSError, IOError):
67+
pass
68+
self.id = IdentDB(full_path("subject.db"), "example.com", "example")
6369

6470
def test_persistent_1(self):
6571
policy = Policy({
@@ -80,9 +86,9 @@ def test_persistent_1(self):
8086
assert nameid.sp_name_qualifier == "urn:mace:example.com:sp:1"
8187
assert nameid.format == NAMEID_FORMAT_PERSISTENT
8288

83-
id = self.id.find_local_id(nameid)
89+
id_ = self.id.find_local_id(nameid)
8490

85-
assert id == "foobar"
91+
assert id_ == "foobar"
8692

8793
def test_persistent_2(self):
8894
userid = 'foobar'
@@ -161,7 +167,6 @@ def test_vo_2(self):
161167
assert nameid.format == NAMEID_FORMAT_PERSISTENT
162168
assert nameid.text != "foobar01"
163169

164-
165170
def test_persistent_nameid(self):
166171
sp_id = "urn:mace:umu.se:sp"
167172
nameid = self.id.persistent_nameid("abcd0001", sp_id)
@@ -187,6 +192,5 @@ def test_transient_nameid(self):
187192
assert nameid.text.strip() != nameid2.text.strip()
188193

189194
def teardown_class(self):
190-
if os.path.exists("subject.db"):
191-
os.unlink("subject.db")
192-
195+
if os.path.exists(full_path("subject.db")):
196+
os.unlink(full_path("subject.db"))

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ envlist =
33
py36
44
py37
55
py38
6+
py39
67
pypy3
78

89
[testenv]

0 commit comments

Comments
 (0)