Skip to content

Commit da768bf

Browse files
committed
Better tests
1 parent 3fbc483 commit da768bf

File tree

1 file changed

+33
-28
lines changed

1 file changed

+33
-28
lines changed

test/unit/test_branches.py

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,34 @@
2929
SUPPORTED_EDITIONS = (c.DE, c.EE, c.DCE)
3030

3131

32+
def verify_branch_support(func: callable, **kwargs) -> bool:
33+
if kwargs["concerned_object"].endpoint.edition() not in SUPPORTED_EDITIONS:
34+
with pytest.raises(exceptions.UnsupportedOperation):
35+
_ = func(**kwargs)
36+
return False
37+
return True
38+
39+
3240
def test_get_object() -> None:
3341
"""Test get_object and verify that if requested twice the same object is returned"""
3442

3543
project = projects.Project.get_object(tutil.SQ, tutil.LIVE_PROJECT)
36-
if not tutil.verify_support(SUPPORTED_EDITIONS, branches.Branch.get_object, endpoint=tutil.SQ, concerned_object=project, branch_name="develop"):
44+
if not verify_branch_support(branches.Branch.get_object, concerned_object=project, branch_name="develop"):
3745
return
38-
obj = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="develop")
39-
assert str(obj) == f"Branch 'develop' of project '{project.key}'"
46+
obj = branches.Branch.get_object(concerned_object=project, branch_name="develop")
47+
assert str(obj) == f"branch 'develop' of project '{project.key}'"
4048
obj.refresh()
4149

4250

4351
def test_not_found() -> None:
4452
project = projects.Project.get_object(tutil.SQ, tutil.LIVE_PROJECT)
45-
if not tutil.verify_support(SUPPORTED_EDITIONS, branches.Branch.get_object, endpoint=tutil.SQ, concerned_object=project, branch_name="develop"):
53+
if not verify_branch_support(branches.Branch.get_object, concerned_object=project, branch_name="develop"):
4654
return
4755
with pytest.raises(exceptions.ObjectNotFound):
48-
obj = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="non-existing")
56+
obj = branches.Branch.get_object(concerned_object=project, branch_name="non-existing")
4957

50-
obj = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="develop")
51-
obj.key = "non-existing2"
58+
obj = branches.Branch.get_object(concerned_object=project, branch_name="develop")
59+
obj.name = "non-existing2"
5260
with pytest.raises(exceptions.ObjectNotFound):
5361
obj.refresh()
5462

@@ -59,10 +67,9 @@ def test_not_found() -> None:
5967

6068
def test_is_main_is_kept():
6169
project = projects.Project.get_object(tutil.SQ, tutil.LIVE_PROJECT)
62-
if not tutil.verify_support(SUPPORTED_EDITIONS, branches.Branch.get_object, endpoint=tutil.SQ, concerned_object=project, branch_name="develop"):
70+
if not verify_branch_support(branches.Branch.get_object, concerned_object=project, branch_name="develop"):
6371
return
64-
with pytest.raises(exceptions.ObjectNotFound):
65-
obj = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="develop")
72+
obj = branches.Branch.get_object(concerned_object=project, branch_name="develop")
6673
obj._keep_when_inactive = None
6774
obj.refresh()
6875
assert obj.is_kept_when_inactive() in (True, False)
@@ -73,10 +80,10 @@ def test_is_main_is_kept():
7380
def test_set_as_main():
7481
"""test_set_as_main"""
7582
project = projects.Project.get_object(tutil.SQ, tutil.LIVE_PROJECT)
76-
if not tutil.verify_support(SUPPORTED_EDITIONS, branches.Branch.get_object, endpoint=tutil.SQ, concerned_object=project, branch_name="develop"):
83+
if not verify_branch_support(branches.Branch.get_object, concerned_object=project, branch_name="develop"):
7784
return
78-
dev_br = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="develop")
79-
master_br = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="master")
85+
dev_br = branches.Branch.get_object(concerned_object=project, branch_name="develop")
86+
master_br = branches.Branch.get_object(concerned_object=project, branch_name="master")
8087
assert master_br.is_main()
8188
assert not dev_br.is_main()
8289

@@ -94,10 +101,10 @@ def test_set_as_main():
94101
def test_set_keep_as_inactive():
95102
"""test_set_keep_as_inactive"""
96103
project = projects.Project.get_object(tutil.SQ, tutil.LIVE_PROJECT)
97-
if not tutil.verify_support(SUPPORTED_EDITIONS, branches.Branch.get_object, endpoint=tutil.SQ, concerned_object=project, branch_name="develop"):
104+
if not verify_branch_support(branches.Branch.get_object, concerned_object=project, branch_name="develop"):
98105
return
99-
dev_br = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="develop")
100-
master_br = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="master")
106+
dev_br = branches.Branch.get_object(concerned_object=project, branch_name="develop")
107+
master_br = branches.Branch.get_object(concerned_object=project, branch_name="master")
101108
assert dev_br.is_kept_when_inactive()
102109
assert master_br.is_kept_when_inactive()
103110

@@ -115,17 +122,17 @@ def test_set_keep_as_inactive():
115122
def test_rename():
116123
"""test_rename"""
117124
project = projects.Project.get_object(tutil.SQ, tutil.LIVE_PROJECT)
118-
if not tutil.verify_support(SUPPORTED_EDITIONS, branches.Branch.get_object, endpoint=tutil.SQ, concerned_object=project, branch_name="develop"):
125+
if not verify_branch_support(branches.Branch.get_object, concerned_object=project, branch_name="develop"):
119126
return
120-
dev_br = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="develop")
121-
master_br = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="master")
127+
dev_br = branches.Branch.get_object(concerned_object=project, branch_name="develop")
128+
master_br = branches.Branch.get_object(concerned_object=project, branch_name="master")
122129
with pytest.raises(exceptions.UnsupportedOperation):
123130
dev_br.rename("release")
124131

125132
assert master_br.rename("main")
126133
assert not master_br.rename("main")
127134

128-
new_br = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="main")
135+
new_br = branches.Branch.get_object(concerned_object=project, branch_name="main")
129136
assert new_br is master_br
130137
assert master_br.rename("master")
131138
assert new_br.name == "master"
@@ -134,31 +141,29 @@ def test_rename():
134141
def test_get_findings():
135142
"""test_get_findings"""
136143
project = projects.Project.get_object(tutil.SQ, tutil.LIVE_PROJECT)
137-
if not tutil.verify_support(SUPPORTED_EDITIONS, branches.Branch.get_object, endpoint=tutil.SQ, concerned_object=project, branch_name="develop"):
144+
if not verify_branch_support(branches.Branch.get_object, concerned_object=project, branch_name="develop"):
138145
return
139-
dev_br = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="develop")
146+
dev_br = branches.Branch.get_object(concerned_object=project, branch_name="develop")
140147
assert len(dev_br.get_findings()) > 0
141148

142149
dev_br.name = "non-existing"
143150
with pytest.raises(exceptions.ObjectNotFound):
144151
dev_br.get_findings()
145152

146153

147-
def test_audit_off():
154+
def test_audit():
148155
"""test_audit_off"""
149156
project = projects.Project.get_object(tutil.SQ, tutil.LIVE_PROJECT)
150-
if not tutil.verify_support(SUPPORTED_EDITIONS, branches.Branch.get_object, endpoint=tutil.SQ, concerned_object=project, branch_name="develop"):
157+
if not verify_branch_support(branches.Branch.get_object, concerned_object=project, branch_name="develop"):
151158
return
152-
dev_br = branches.Branch.get_object(endpoint=tutil.SQ, concerned_object=project, branch_name="develop")
159+
dev_br = branches.Branch.get_object(concerned_object=project, branch_name="develop")
153160
assert len(dev_br.audit({"audit.project.branches": False})) == 0
154161

155162
dev_br.name = "non-existing"
156-
with pytest.raises(exceptions.ObjectNotFound):
157-
dev_br.audit({})
163+
assert len(dev_br.audit({})) == 0
158164

159165

160166
def test_exists():
161167
"""test_exists"""
162168
assert branches.exists(tutil.SQ, branch_name="develop", project_key=tutil.LIVE_PROJECT)
163169
assert not branches.exists(tutil.SQ, branch_name="foobar", project_key=tutil.LIVE_PROJECT)
164-
assert not branches.exists(tutil.SQ, branch_name="develop", project_key=tutil.PROJECT_1)

0 commit comments

Comments
 (0)