Skip to content

Commit 5f89e28

Browse files
crazyscientistcrobinso
authored andcommitted
test: Use a class to organize tests in test_backend_rest.py
1 parent 567cfd6 commit 5f89e28

1 file changed

Lines changed: 27 additions & 18 deletions

File tree

tests/test_backend_rest.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,41 @@
44
from bugzilla._session import _BugzillaSession
55

66

7-
def test_getbug():
8-
session = _BugzillaSession(url="http://example.com",
7+
class TestGetBug:
8+
@property
9+
def session(self):
10+
return _BugzillaSession(url="http://example.com",
911
user_agent="py-bugzilla-test",
1012
sslverify=False,
1113
cert=None,
1214
tokencache={},
1315
api_key="",
1416
is_redhat_bugzilla=False)
15-
backend = _BackendREST(url="http://example.com",
16-
bugzillasession=session)
1717

18-
def _assertion(self, *args):
19-
self.assertion_called = True
20-
assert args and args[0] == url
18+
@property
19+
def backend(self):
20+
return _BackendREST(url="http://example.com",
21+
bugzillasession=self.session)
2122

22-
setattr(backend, "_get", MethodType(_assertion, backend))
23+
def test_getbug__not_permissive(self):
24+
backend = self.backend
2325

24-
for _ids, aliases, url in (
25-
(1, None, "/bug/1"),
26-
([1], [], "/bug/1"),
27-
(None, "CVE-1999-0001", "/bug/CVE-1999-0001"),
28-
([], ["CVE-1999-0001"], "/bug/CVE-1999-0001"),
29-
(1, "CVE-1999-0001", "/bug"),
30-
):
31-
backend.assertion_called = False
26+
def _assertion(self, *args):
27+
self.assertion_called = True
28+
assert args and args[0] == url
3229

33-
backend.bug_get(_ids, aliases, {})
30+
setattr(backend, "_get", MethodType(_assertion, backend))
3431

35-
assert backend.assertion_called is True
32+
for _ids, aliases, url in (
33+
(1, None, "/bug/1"),
34+
([1], [], "/bug/1"),
35+
(None, "CVE-1999-0001", "/bug/CVE-1999-0001"),
36+
([], ["CVE-1999-0001"], "/bug/CVE-1999-0001"),
37+
(1, "CVE-1999-0001", "/bug"),
38+
([1, 2], None, "/bug")
39+
):
40+
backend.assertion_called = False
41+
42+
backend.bug_get(_ids, aliases, {})
43+
44+
assert backend.assertion_called is True

0 commit comments

Comments
 (0)