Skip to content

Commit 2d3ba4e

Browse files
crazyscientistcrobinso
authored andcommitted
ci: More functional tests
Migrated all generic functional RO tests to the new integration suite. Also, added a comment to the old tests to indicate which integration test corresponds to it.
1 parent 8f77896 commit 2d3ba4e

5 files changed

Lines changed: 111 additions & 3 deletions

File tree

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def status_callback(request):
141141

142142
test_url = os.getenv("BUGZILLA_URL")
143143
if test_url:
144-
passthrough += (test_url, )
144+
passthrough += (test_url, test_url.replace("http://", "https://"))
145145
with responses.RequestsMock(passthru_prefixes=passthrough,
146146
assert_all_requests_are_fired=False) as mock:
147147
mock.add_callback(

tests/integration/ro_api_test.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Ignoring pytest-related warnings:
22
# pylint: disable=redefined-outer-name,unused-argument
3+
from urllib.parse import urljoin
34
from xmlrpc.client import Fault
45

56
import pytest
@@ -62,6 +63,18 @@ def test_get_products(mocked_responses, backends):
6263
assert {v["name"] for v in rhel["versions"]} == {"9.0", "9.1", "unspecified"}
6364

6465

66+
def test_get_product(mocked_responses, backends):
67+
bz = open_bz(url=TEST_URL, **backends)
68+
69+
product_ids = {product["id"] for product in bz.product_get(ptype="enterable",
70+
include_fields=["id"])}
71+
product_names = {product["name"] for product in bz.product_get(ptype="selectable",
72+
include_fields=["name"])}
73+
assert product_ids == {1, 2, 3}
74+
assert product_names == {'Red Hat Enterprise Linux 9', 'SUSE Linux Enterprise Server 15 SP6',
75+
'TestProduct'}
76+
77+
6578
def test_get_components(mocked_responses, backends):
6679
bz = open_bz(url=TEST_URL, **backends)
6780
components = bz.getcomponents(product="SUSE Linux Enterprise Server 15 SP6")
@@ -106,6 +119,16 @@ def test_get_bug_alias(mocked_responses, backends):
106119
assert bug.summary == "ZeroDivisionError in function foo_bar()"
107120

108121

122+
def test_bug_url(mocked_responses, backends):
123+
bz = open_bz(url=TEST_URL, **backends)
124+
bug_id = 2
125+
126+
# Ensure weburl is generated consistently whether
127+
# we are using XMLRPC or REST
128+
bug = bz.getbug(bug_id)
129+
assert bug.weburl == urljoin(TEST_URL, f"/show_bug.cgi?id={bug_id}")
130+
131+
109132
def test_get_bug_alias_included_field(mocked_responses, backends):
110133
bug_id, alias = 1, "FOO-1"
111134
bz = open_bz(url=TEST_URL, **backends)
@@ -117,6 +140,18 @@ def test_get_bug_alias_included_field(mocked_responses, backends):
117140
assert not hasattr(bug, "summary")
118141

119142

143+
def test_get_bug_exclude_fields(mocked_responses, backends):
144+
bz = open_bz(url=TEST_URL, **backends)
145+
146+
# Check default extra_fields will pull in comments
147+
bug = bz.getbug(2, exclude_fields=["product"])
148+
assert not hasattr(bug, "product")
149+
150+
# Ensure that include_fields overrides default extra_fields
151+
bug = bz.getbug(2)
152+
assert hasattr(bug, "product")
153+
154+
120155
def test_get_bug_404(mocked_responses, backends):
121156
bz = open_bz(url=TEST_URL, **backends)
122157
try:
@@ -147,3 +182,39 @@ def test_get_bug_fields(mocked_responses, backends):
147182
assert fields == ["product"]
148183
bz.getbugfields(names=["product", "bug_status"], force_refresh=True)
149184
assert set(bz.bugfields) == {"product", "bug_status"}
185+
186+
187+
def test_query_autorefresh(mocked_responses, backends):
188+
bz = open_bz(url=TEST_URL, **backends)
189+
190+
bz.bug_autorefresh = True
191+
bug = bz.query(bz.build_query(bug_id=1, include_fields=["summary"]))[0]
192+
assert hasattr(bug, "component")
193+
assert bool(bug.component)
194+
195+
bz.bug_autorefresh = False
196+
bug = bz.query(bz.build_query(bug_id=1, include_fields=["summary"]))[0]
197+
assert not hasattr(bug, "component")
198+
try:
199+
assert bool(bug.component)
200+
except Exception as e:
201+
assert "adjust your include_fields" in str(e)
202+
203+
204+
def test_login_stubs(mocked_responses, backends):
205+
# Explicitly set configpaths to avoid interference with an API key set by another test
206+
bz = open_bz(url=TEST_URL, configpaths="/dev/null", **backends)
207+
bz_apikey = open_bz(url=TEST_URL, api_key="random-and-secure-api-key", **backends)
208+
209+
# Failed login, verifies our backends are calling the correct API
210+
with pytest.raises(BugzillaError) as e:
211+
bz.login("foo", "bar")
212+
assert "Login failed" in str(e)
213+
214+
# Login is prohibited, when an API key is defined
215+
with pytest.raises(ValueError) as e:
216+
bz_apikey.login("foo", "bar")
217+
assert "cannot login when using an API key" in str(e)
218+
219+
# Works fine when not logged in
220+
bz.logout()

tests/integration/ro_cli_test.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
11
# Ignoring pytest-related warnings:
22
# pylint: disable=unused-argument
33
import re
4-
from urllib.parse import urljoin
4+
from urllib.parse import urljoin, urlparse, urlunparse
55

66
from ..utils import open_bz
77
from . import TEST_URL, TEST_PRODUCTS, TEST_SUSE_COMPONENTS, TEST_OWNER
88

99

10+
def test_fails(mocked_responses, run_cli, backends):
11+
bz = open_bz(url=TEST_URL, **backends)
12+
out = run_cli("bugzilla query --field=IDONTEXIST=FOO", bzinstance=bz, expectfail=True)
13+
assert "Server error:" in out
14+
15+
out = run_cli("bugzilla --bugzilla https://example.com/xmlrpc.cgi query --field=IDONTEXIST=FOO",
16+
bzinstance=None, expectfail=True)
17+
assert "Connection lost/failed" in out
18+
19+
parsed = urlparse(TEST_URL)
20+
netloc = parsed.netloc
21+
if not re.search(r":\d+$", netloc):
22+
netloc += ":80"
23+
24+
https_test_url = urlunparse(("https", netloc, parsed.path, parsed.params, parsed.query,
25+
parsed.fragment))
26+
out = run_cli(f"bugzilla --bugzilla {https_test_url} query --bug_id 1234",
27+
bzinstance=None, expectfail=True)
28+
assert "trust the remote server" in out
29+
assert "--nosslverify" in out
30+
31+
1032
def test_get_products(mocked_responses, run_cli, backends):
1133
bz = open_bz(url=TEST_URL, **backends)
1234
out = run_cli("bugzilla info --products", bzinstance=bz)
@@ -24,6 +46,14 @@ def test_get_components(mocked_responses, run_cli, backends):
2446
assert comp in out
2547

2648

49+
def test_get_active_components(mocked_responses, run_cli, backends):
50+
bz = open_bz(url=TEST_URL, **backends)
51+
out = run_cli("bugzilla info --components 'SUSE Linux Enterprise Server 15 SP6' "
52+
"--active-components", bzinstance=bz)
53+
assert "Containers" in out
54+
assert "Kernel" in out
55+
56+
2757
def test_get_component_owners(mocked_responses, run_cli, backends):
2858
bz = open_bz(url=TEST_URL, **backends)
2959
out = run_cli("bugzilla info --component_owners 'SUSE Linux Enterprise Server 15 SP6'",

tests/services/params.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"quip_list_entry_control" : "open",
7070
"rememberlogin" : "on",
7171
"requirelogin" : "0",
72-
"search_allow_no_criteria" : "1",
72+
"search_allow_no_criteria" : "0",
7373
"shadowdb" : "",
7474
"shadowdbhost" : "",
7575
"shadowdbport" : "3306",

tests/test_ro_functional.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,15 @@ def testBugFields(backends):
387387
assert set(bz.bugfields) == set(["product", "bug_status"])
388388

389389

390+
# See also: tests/integration/ro_api_test.py::test_get_product
390391
def testProductGetMisc(backends):
391392
bz = _open_bz(REDHAT_URL, **backends)
392393

393394
assert bz.product_get(ptype="enterable", include_fields=["id"])
394395
assert bz.product_get(ptype="selectable", include_fields=["name"])
395396

396397

398+
# See also: tests/integration/ro_api_test.py::test_query_autorefresh
397399
def testBugAutoRefresh(backends):
398400
bz = _open_bz(REDHAT_URL, **backends)
399401

@@ -415,6 +417,7 @@ def testBugAutoRefresh(backends):
415417
assert "adjust your include_fields" in str(e)
416418

417419

420+
# See also (in part): tests/integration/ro_api_test.py::test_get_bug_exclude_fields
418421
def testExtraFields(backends):
419422
bz = _open_bz(REDHAT_URL, **backends)
420423

@@ -438,6 +441,7 @@ def testExternalBugsOutput(run_cli, backends):
438441
assert "External bug: https://bugs.launchpad.net/bugs/1203576" in out
439442

440443

444+
# See also: tests/integration/ro_cli_test.py::test_get_active_components
441445
def testActiveComps(run_cli, backends):
442446
bz = _open_bz(REDHAT_URL, **backends)
443447

@@ -449,6 +453,7 @@ def testActiveComps(run_cli, backends):
449453
assert "virtinst" not in out
450454

451455

456+
# See also: tests/integration/ro_cli_test.py::test_fails
452457
def testFaults(run_cli, backends):
453458
bz = _open_bz(REDHAT_URL, **backends)
454459

@@ -469,6 +474,7 @@ def testFaults(run_cli, backends):
469474
assert "--nosslverify" in out
470475

471476

477+
# See also: tests/integration/ro_api_test.py::test_login_stubs
472478
def test_login_stubs(backends):
473479
bz = _open_bz(REDHAT_URL, **backends)
474480

@@ -489,6 +495,7 @@ def test_redhat_version(backends):
489495
_test_version(bz, bzversion)
490496

491497

498+
# See also: tests/integration/ro_api_test.py::test_bug_url
492499
def test_bug_misc(backends):
493500
bz = _open_bz(REDHAT_URL, **backends)
494501

0 commit comments

Comments
 (0)