-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathrw_api_test.py
More file actions
120 lines (85 loc) · 3.25 KB
/
Copy pathrw_api_test.py
File metadata and controls
120 lines (85 loc) · 3.25 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# pylint: disable=unused-argument
from uuid import uuid4
from xmlrpc.client import Fault
from pytest import raises
from pytest import mark
from bugzilla import Bugzilla, BugzillaError
from bugzilla.bug import Bug
from ..utils import open_bz
from . import TEST_URL
# NOTE: The tests in this file assume that an API key is defined in the bugzillarc!
DEFAULT_PARAMS = {"product": "TestProduct",
"component": "TestComponent",
"version": "unspecified",
"summary": "A new bug",
"description": "Details on how to reproduce",
"cc": "nemo@example.com",
"op_sys": "Linux",
"platform": "PC"}
def _create_bug(bz: Bugzilla, **kwargs) -> Bug:
"""
Create a new bug with overwrite-able defaults
"""
params = DEFAULT_PARAMS.copy()
params.update(kwargs)
return bz.createbug(**bz.build_createbug(**params))
def test_create_bug(mocked_responses, backends):
bz = open_bz(url=TEST_URL, **backends)
bug = _create_bug(bz)
assert isinstance(bug, Bug)
assert bug.id
bug = bz.getbug(bug.id)
for field in ("product", "component", "version", "summary"):
assert getattr(bug, field) == DEFAULT_PARAMS[field]
def test_create_bug_anonymous(mocked_responses, backends):
bz = open_bz(url=TEST_URL, configpaths="/dev/null", **backends)
with raises((Fault, BugzillaError)):
_create_bug(bz)
def test_create_bug_alias(mocked_responses, backends):
bz = open_bz(url=TEST_URL, **backends)
alias = uuid4().hex
bug = _create_bug(bz, alias=alias)
bug = bz.getbug(bug.id)
assert alias in bug.alias
with raises((Fault, BugzillaError)):
_create_bug(bz, alias=alias)
def test_update_bug(mocked_responses, backends):
email = "nemo@example.com"
bz = open_bz(url=TEST_URL, **backends)
bug = _create_bug(bz)
params = bz.build_update(resolution="WONTFIX", status="RESOLVED", cc_remove=email)
bz.update_bugs(bug.id, params)
bug.refresh()
assert bug.resolution == "WONTFIX"
assert bug.status == "RESOLVED"
assert bug.cc == []
params = bz.build_update(cc_add=email)
bz.update_bugs(bug.id, params)
bug.refresh()
assert bug.cc == [email]
# Bugzilla instance has no CLOSED status
@mark.xfail
def test_close_bug(mocked_responses, backends):
bz = open_bz(url=TEST_URL, **backends)
bug = _create_bug(bz)
bug.close(resolution="WORKSFORME", comment="Bla bla", isprivate=True)
bug.refresh()
assert bug.resolution == "WORKSFORME"
assert bug.status == "CLOSED"
def test_add_comment(mocked_responses, backends):
bz = open_bz(url=TEST_URL, **backends)
bug = bz.getbug(1)
comment_count = len(bug.get_comments())
bug.addcomment("Bla Bla bla", private=True)
bug.refresh()
assert len(bug.get_comments()) == comment_count + 1
def test_update_flags(mocked_responses, backends):
bz = open_bz(url=TEST_URL, **backends)
bug = _create_bug(bz)
flag = {"requestee": "nemo@example.com", "name": "needinfo", "status": "?"}
params = bz.build_update(flags=[flag])
bz.update_bugs([bug.id], params)
bug.refresh()
assert len(bug.flags) == 1
for key, value in flag.items():
assert bug.flags[0][key] == value