-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathtest_backend_rest.py
More file actions
67 lines (51 loc) · 2.34 KB
/
test_backend_rest.py
File metadata and controls
67 lines (51 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from types import MethodType
from bugzilla._backendrest import _BackendREST
from bugzilla._session import _BugzillaSession
class TestGetBug:
@property
def session(self):
return _BugzillaSession(url="http://example.com",
user_agent="py-bugzilla-test",
sslverify=False,
cert=None,
tokencache={},
api_key="",
is_redhat_bugzilla=False)
@property
def backend(self):
return _BackendREST(url="http://example.com",
bugzillasession=self.session)
def test_getbug__not_permissive(self):
backend = self.backend
def _assertion(self, *args):
self.assertion_called = True
assert args and args[0] == url
setattr(backend, "_get", MethodType(_assertion, backend))
for _ids, aliases, url in (
(1, None, "/bug/1"),
([1], [], "/bug/1"),
(None, "CVE-1999-0001", "/bug/CVE-1999-0001"),
([], ["CVE-1999-0001"], "/bug/CVE-1999-0001"),
(1, "CVE-1999-0001", "/bug"),
([1, 2], None, "/bug")
):
backend.assertion_called = False
backend.bug_get(_ids, aliases, {})
assert backend.assertion_called is True
def test_getbug__permissive(self):
backend = self.backend
def _assertion(self, *args):
self.assertion_called = True
assert args and args[0] == url and args[1] == params
setattr(backend, "_get", MethodType(_assertion, backend))
for _ids, aliases, url, params in (
(1, None, "/bug", {"id": [1], "alias": None}),
([1], [], "/bug", {"id": [1], "alias": []}),
(None, "CVE-1999-0001", "/bug", {"alias": ["CVE-1999-0001"], "id": None}),
([], ["CVE-1999-0001"], "/bug", {"alias": ["CVE-1999-0001"], "id": []}),
(1, "CVE-1999-0001", "/bug", {"id": [1], "alias": ["CVE-1999-0001"]}),
([1, 2], None, "/bug", {"id": [1, 2], "alias": None})
):
backend.assertion_called = False
backend.bug_get(_ids, aliases, {"permissive": True})
assert backend.assertion_called is True