CI: Added RW integration tests · klsbecker/python-bugzilla@35c4510 · GitHub
Skip to content

Commit 35c4510

Browse files
crazyscientistcrobinso
authored andcommitted
CI: Added RW integration tests
* Migrated some RW tests from test_rw_functional.py * Run RW tests in CI * Updated Bugzilla parameter to allow tagging of comments * Use TestProduct for RW tests
1 parent 98de1e2 commit 35c4510

6 files changed

Lines changed: 142 additions & 3 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions

tests/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
def pytest_addoption(parser):
2222
parser.addoption("--ro-integration", action="store_true", default=False,
2323
help="Run readonly tests against local Bugzilla instance.")
24+
parser.addoption("--rw-integration", action="store_true", default=False,
25+
help="Run read-write tests against local Bugzilla instance.")
2426
parser.addoption("--ro-functional", action="store_true", default=False,
2527
help=("Run readonly functional tests against actual "
2628
"bugzilla instances. This will be very slow."))
@@ -46,14 +48,18 @@ def pytest_ignore_collect(collection_path, config):
4648
has_ro = config.getoption("--ro-functional")
4749
has_ro_i = config.getoption("--ro-integration")
4850
has_rw = config.getoption("--rw-functional")
51+
has_rw_i = config.getoption("--rw-integration")
4952

5053
base = os.path.basename(str(collection_path))
5154
is_ro = base == "test_ro_functional.py"
5255
is_ro_i = "tests/integration/ro" in str(collection_path)
5356
is_rw = base == "test_rw_functional.py"
57+
is_rw_i = "tests/integration/rw" in str(collection_path)
5458

5559
if is_ro_i and not has_ro_i:
5660
return True
61+
if is_rw_i and not has_rw_i:
62+
return True
5763

5864
if is_ro and not has_ro:
5965
return True

tests/integration/ro_api_test.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ def test_query_autorefresh(mocked_responses, backends):
201201
assert "adjust your include_fields" in str(e)
202202

203203

204+
def test_logged_in_no_creds(mocked_responses, backends):
205+
bz = open_bz(url=TEST_URL, use_creds=False, **backends)
206+
assert not bz.logged_in
207+
208+
204209
def test_login_stubs(mocked_responses, backends):
205210
# Explicitly set configpaths to avoid interference with an API key set by another test
206211
bz = open_bz(url=TEST_URL, configpaths="/dev/null", **backends)

tests/integration/rw_api_test.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# pylint: disable=unused-argument
2+
from uuid import uuid4
3+
from xmlrpc.client import Fault
4+
5+
from pytest import raises
6+
from pytest import mark
7+
8+
from bugzilla import Bugzilla, BugzillaError
9+
from bugzilla.bug import Bug
10+
11+
from ..utils import open_bz
12+
from . import TEST_URL
13+
14+
# NOTE: The tests in this file assume that an API key is defined in the bugzillarc!
15+
16+
17+
DEFAULT_PARAMS = {"product": "TestProduct",
18+
"component": "TestComponent",
19+
"version": "unspecified",
20+
"summary": "A new bug",
21+
"description": "Details on how to reproduce",
22+
"cc": "nemo@example.com",
23+
"op_sys": "Linux",
24+
"platform": "PC"}
25+
26+
27+
def _create_bug(bz: Bugzilla, **kwargs) -> Bug:
28+
"""
29+
Create a new bug with overwrite-able defaults
30+
"""
31+
params = DEFAULT_PARAMS.copy()
32+
params.update(kwargs)
33+
34+
return bz.createbug(**bz.build_createbug(**params))
35+
36+
37+
def test_create_bug(mocked_responses, backends):
38+
bz = open_bz(url=TEST_URL, **backends)
39+
bug = _create_bug(bz)
40+
41+
assert isinstance(bug, Bug)
42+
assert bug.id
43+
44+
bug = bz.getbug(bug.id)
45+
for field in ("product", "component", "version", "summary"):
46+
assert getattr(bug, field) == DEFAULT_PARAMS[field]
47+
48+
49+
def test_create_bug_anonymous(mocked_responses, backends):
50+
bz = open_bz(url=TEST_URL, configpaths="/dev/null", **backends)
51+
with raises((Fault, BugzillaError)):
52+
_create_bug(bz)
53+
54+
55+
def test_create_bug_alias(mocked_responses, backends):
56+
bz = open_bz(url=TEST_URL, **backends)
57+
alias = uuid4().hex
58+
bug = _create_bug(bz, alias=alias)
59+
60+
bug = bz.getbug(bug.id)
61+
assert alias in bug.alias
62+
63+
with raises((Fault, BugzillaError)):
64+
_create_bug(bz, alias=alias)
65+
66+
67+
def test_update_bug(mocked_responses, backends):
68+
email = "nemo@example.com"
69+
bz = open_bz(url=TEST_URL, **backends)
70+
bug = _create_bug(bz)
71+
params = bz.build_update(resolution="WONTFIX", status="RESOLVED", cc_remove=email)
72+
bz.update_bugs(bug.id, params)
73+
bug.refresh()
74+
75+
assert bug.resolution == "WONTFIX"
76+
assert bug.status == "RESOLVED"
77+
assert bug.cc == []
78+
79+
params = bz.build_update(cc_add=email)
80+
bz.update_bugs(bug.id, params)
81+
bug.refresh()
82+
83+
assert bug.cc == [email]
84+
85+
86+
# Bugzilla instance has no CLOSED status
87+
@mark.xfail
88+
def test_close_bug(mocked_responses, backends):
89+
bz = open_bz(url=TEST_URL, **backends)
90+
bug = _create_bug(bz)
91+
bug.close(resolution="WORKSFORME", comment="Bla bla", isprivate=True)
92+
bug.refresh()
93+
94+
assert bug.resolution == "WORKSFORME"
95+
assert bug.status == "CLOSED"
96+
97+
98+
def test_add_comment(mocked_responses, backends):
99+
bz = open_bz(url=TEST_URL, **backends)
100+
bug = bz.getbug(1)
101+
102+
comment_count = len(bug.get_comments())
103+
bug.addcomment("Bla Bla bla", private=True)
104+
bug.refresh()
105+
106+
assert len(bug.get_comments()) == comment_count + 1
107+
108+
109+
def test_update_flags(mocked_responses, backends):
110+
bz = open_bz(url=TEST_URL, **backends)
111+
bug = _create_bug(bz)
112+
flag = {"requestee": "nemo@example.com", "name": "needinfo", "status": "?"}
113+
params = bz.build_update(flags=[flag])
114+
bz.update_bugs([bug.id], params)
115+
bug.refresh()
116+
117+
assert len(bug.flags) == 1
118+
119+
for key, value in flag.items():
120+
assert bug.flags[0][key] == value

tests/services/params.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"font_file" : "",
4545
"globalwatchers" : "",
4646
"inbound_proxies" : "",
47-
"insidergroup" : "",
47+
"insidergroup" : "editbugs",
4848
"last_visit_keep_days" : "10",
4949
"letsubmitterchoosemilestone" : "1",
5050
"letsubmitterchoosepriority" : "1",

tests/test_rw_functional.py

Lines changed: 8 additions & 0 deletions

0 commit comments

Comments
 (0)