Skip to content

Commit 8f77896

Browse files
ci: More functional tests
Migrated more functional RO tests to the new integration suite. Also, added a comment to the old tests to indicate which integration test corresponds to it. Updated the SQL fixture accordingly. And fixed a typo in the README.
1 parent 7b8d18e commit 8f77896

5 files changed

Lines changed: 161 additions & 29 deletions

File tree

tests/integration/ro_api_test.py

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Ignoring pytest-related warnings:
22
# pylint: disable=redefined-outer-name,unused-argument
3+
from xmlrpc.client import Fault
4+
35
import pytest
46

57
from bugzilla import BugzillaError
@@ -85,7 +87,7 @@ def test_query(mocked_responses, backends):
8587
assert bugs[0].summary == "Expect the Spanish inquisition"
8688

8789
bz = open_bz(url=TEST_URL, **backends)
88-
query = bz.build_query(product="SUSE Linux Enterprise Server 15 SP6")
90+
query = bz.build_query(product="SUSE Linux Enterprise Server 15 SP6", component="Containers")
8991
bugs = bz.query(query=query)
9092

9193
assert len(bugs) == 1
@@ -94,8 +96,54 @@ def test_query(mocked_responses, backends):
9496

9597

9698
def test_get_bug_alias(mocked_responses, backends):
99+
bug_id, alias = 1, "FOO-1"
97100
bz = open_bz(url=TEST_URL, **backends)
98-
bug = bz.getbug("FOO-1")
101+
bug = bz.getbug(alias)
99102

100-
assert bug.id == 1
103+
assert bug.id == bug_id
104+
assert bug.bug_id == bug_id
105+
assert bug.alias == [alias]
101106
assert bug.summary == "ZeroDivisionError in function foo_bar()"
107+
108+
109+
def test_get_bug_alias_included_field(mocked_responses, backends):
110+
bug_id, alias = 1, "FOO-1"
111+
bz = open_bz(url=TEST_URL, **backends)
112+
bug = bz.getbug(alias, include_fields=["id"])
113+
114+
assert bug.id == bug_id
115+
assert bug.bug_id == bug_id
116+
assert bug.alias == [alias]
117+
assert not hasattr(bug, "summary")
118+
119+
120+
def test_get_bug_404(mocked_responses, backends):
121+
bz = open_bz(url=TEST_URL, **backends)
122+
try:
123+
bz.getbug(666)
124+
except Fault as error: # XMLRPC API
125+
assert error.faultCode == 101
126+
except BugzillaError as error: # REST API
127+
assert error.code == 101
128+
else:
129+
raise AssertionError("No exception raised")
130+
131+
132+
def test_get_bug_alias_404(mocked_responses, backends):
133+
bz = open_bz(url=TEST_URL, **backends)
134+
try:
135+
bz.getbug("CVE-1234-4321")
136+
except Fault as error: # XMLRPC API
137+
assert error.faultCode == 100
138+
except BugzillaError as error: # REST API
139+
assert error.code == 100
140+
else:
141+
raise AssertionError("No exception raised")
142+
143+
144+
def test_get_bug_fields(mocked_responses, backends):
145+
bz = open_bz(url=TEST_URL, **backends)
146+
fields = bz.getbugfields(names=["product"])
147+
assert fields == ["product"]
148+
bz.getbugfields(names=["product", "bug_status"], force_refresh=True)
149+
assert set(bz.bugfields) == {"product", "bug_status"}

tests/integration/ro_cli_test.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Ignoring pytest-related warnings:
22
# pylint: disable=unused-argument
3+
import re
4+
from urllib.parse import urljoin
5+
36
from ..utils import open_bz
47
from . import TEST_URL, TEST_PRODUCTS, TEST_SUSE_COMPONENTS, TEST_OWNER
58

@@ -45,3 +48,57 @@ def test_query(mocked_responses, run_cli, backends):
4548
assert len(lines) == 1
4649
assert lines[0].startswith("#2")
4750
assert "Expect the Spanish inquisition" in lines[0]
51+
52+
53+
def test_query_full(mocked_responses, run_cli, backends):
54+
bz = open_bz(url=TEST_URL, **backends)
55+
out = run_cli("bugzilla query --full --bug_id 2", bzinstance=bz)
56+
lines = out.strip().splitlines()
57+
assert len(lines) == 5
58+
59+
for name in ('Component', 'CC', 'Blocked', 'Depends'):
60+
assert name in out
61+
62+
assert "Status Whiteboard" not in out
63+
64+
65+
def test_query_raw(mocked_responses, run_cli, backends):
66+
bz = open_bz(url=TEST_URL, **backends)
67+
out = run_cli("bugzilla query --raw --bug_id 2", bzinstance=bz)
68+
69+
assert "ATTRIBUTE[whiteboard]: lorem ipsum" in out
70+
assert "ATTRIBUTE[id]: 2" in out
71+
72+
73+
def test_query_oneline(mocked_responses, run_cli, backends):
74+
bz = open_bz(url=TEST_URL, **backends)
75+
out = run_cli("bugzilla query --oneline --bug_id 2", bzinstance=bz)
76+
lines = out.strip().splitlines()
77+
assert len(lines) == 1
78+
assert "python-bugzilla" in lines[0]
79+
80+
81+
def test_query_extra(mocked_responses, run_cli, backends):
82+
bz = open_bz(url=TEST_URL, **backends)
83+
out = run_cli("bugzilla query --extra --bug_id 2", bzinstance=bz)
84+
lines = out.strip().splitlines()
85+
assert len(lines) == 5
86+
assert "Keywords: FooBar" in out
87+
assert "Status Whiteboard: lorem ipsum" in out
88+
89+
90+
def test_query_format(mocked_responses, run_cli, backends):
91+
bz = open_bz(url=TEST_URL, **backends)
92+
out = run_cli("bugzilla query --outputformat=\"id=%{bug_id} "
93+
"sw=%{whiteboard:status} needinfo=%{flag:needinfo} "
94+
"sum=%{summary}\" --bug_id 2", bzinstance=bz)
95+
lines = out.strip().splitlines()
96+
assert len(lines) == 1
97+
assert out.strip() == "id=2 sw=lorem ipsum needinfo=? sum=Expect the Spanish inquisition"
98+
99+
100+
def test_query_url(mocked_responses, run_cli, backends):
101+
url = urljoin(TEST_URL, "/buglist.cgi?version=9.1")
102+
bz = open_bz(url=TEST_URL, **backends)
103+
out = run_cli(f"bugzilla query --from-url \"{url}\"", bzinstance=bz)
104+
assert re.search(r"#2\s+CONFIRMED", out)

tests/services/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Bugzilla container and edit the data in Bugzilla. Once done, one needs to dump t
4747
the file again:
4848

4949
```shell
50-
$ mariadb-dump -u bugs -h 127.0.0.1 -P 3306 --password=secret bugs > bugs.qql
50+
$ mariadb-dump -u bugs -h 127.0.0.1 -P 3306 --password=secret bugs > bugs.sql
5151
```
5252

5353
## Testing

0 commit comments

Comments
 (0)