|
| 1 | +# Ignoring pytest-related warnings: |
| 2 | +# pylint: disable=redefined-outer-name,unused-argument |
| 3 | +import pytest |
| 4 | + |
| 5 | +from bugzilla import BugzillaError |
| 6 | + |
| 7 | +from ..utils import open_bz |
| 8 | +from . import TEST_URL, TEST_PRODUCTS, TEST_SUSE_COMPONENTS, TEST_OWNER |
| 9 | + |
| 10 | + |
| 11 | +def test_rest_xmlrpc_detection(mocked_responses): |
| 12 | + # The default: use XMLRPC |
| 13 | + bz = open_bz(url=TEST_URL) |
| 14 | + assert bz.is_xmlrpc() |
| 15 | + assert "/xmlrpc.cgi" in bz.url |
| 16 | + |
| 17 | + # See /rest in the URL, so use REST |
| 18 | + bz = open_bz(url=TEST_URL + "/rest") |
| 19 | + assert bz.is_rest() |
| 20 | + with pytest.raises(BugzillaError) as e: |
| 21 | + dummy = bz._proxy # pylint: disable=protected-access |
| 22 | + assert "raw XMLRPC access is not provided" in str(e) |
| 23 | + |
| 24 | + # See /xmlrpc.cgi in the URL, so use XMLRPC |
| 25 | + bz = open_bz(url=TEST_URL + "/xmlrpc.cgi") |
| 26 | + assert "/xmlrpc.cgi" in bz.url |
| 27 | + assert bz.is_xmlrpc() |
| 28 | + assert bz._proxy # pylint: disable=protected-access |
| 29 | + |
| 30 | + |
| 31 | +def test_apikey_error_scraping(mocked_responses): |
| 32 | + # Ensure the API key does not leak into any requests exceptions |
| 33 | + fakekey = "FOOBARMYKEY" |
| 34 | + with pytest.raises(Exception) as e: |
| 35 | + open_bz("https://httpstat.us/400&foo", |
| 36 | + force_xmlrpc=True, api_key=fakekey) |
| 37 | + assert "Client Error" in str(e.value) |
| 38 | + assert fakekey not in str(e.value) |
| 39 | + |
| 40 | + with pytest.raises(Exception) as e: |
| 41 | + open_bz("https://httpstat.us/400&foo", |
| 42 | + force_rest=True, api_key=fakekey) |
| 43 | + assert "Client Error" in str(e.value) |
| 44 | + assert fakekey not in str(e.value) |
| 45 | + |
| 46 | + |
| 47 | +def test_xmlrpc_bad_url(mocked_responses): |
| 48 | + with pytest.raises(BugzillaError) as e: |
| 49 | + open_bz(url="https://example.com/#xmlrpc", force_xmlrpc=True) |
| 50 | + assert "URL may not be an XMLRPC URL" in str(e) |
| 51 | + |
| 52 | + |
| 53 | +def test_get_products(mocked_responses, backends): |
| 54 | + bz = open_bz(url=TEST_URL, **backends) |
| 55 | + |
| 56 | + assert len(bz.products) == 3 |
| 57 | + assert {p["name"] for p in bz.products} == TEST_PRODUCTS |
| 58 | + |
| 59 | + rhel = next(p for p in bz.products if p["id"] == 2) |
| 60 | + assert {v["name"] for v in rhel["versions"]} == {"9.0", "9.1", "unspecified"} |
| 61 | + |
| 62 | + |
| 63 | +def test_get_components(mocked_responses, backends): |
| 64 | + bz = open_bz(url=TEST_URL, **backends) |
| 65 | + components = bz.getcomponents(product="SUSE Linux Enterprise Server 15 SP6") |
| 66 | + assert len(components) == 2 |
| 67 | + assert set(components) == TEST_SUSE_COMPONENTS |
| 68 | + |
| 69 | + |
| 70 | +def test_get_component_detail(mocked_responses, backends): |
| 71 | + bz = open_bz(url=TEST_URL, **backends) |
| 72 | + component = bz.getcomponentdetails(product="Red Hat Enterprise Linux 9", |
| 73 | + component="python-bugzilla") |
| 74 | + assert component["id"] == 2 |
| 75 | + assert component["default_assigned_to"] == TEST_OWNER |
| 76 | + |
| 77 | + |
| 78 | +def test_query(mocked_responses, backends): |
| 79 | + bz = open_bz(url=TEST_URL, **backends) |
| 80 | + query = bz.build_query(product="Red Hat Enterprise Linux 9", component="python-bugzilla") |
| 81 | + bugs = bz.query(query=query) |
| 82 | + |
| 83 | + assert len(bugs) == 1 |
| 84 | + assert bugs[0].id == 2 |
| 85 | + assert bugs[0].summary == "Expect the Spanish inquisition" |
| 86 | + |
| 87 | + bz = open_bz(url=TEST_URL, **backends) |
| 88 | + query = bz.build_query(product="SUSE Linux Enterprise Server 15 SP6") |
| 89 | + bugs = bz.query(query=query) |
| 90 | + |
| 91 | + assert len(bugs) == 1 |
| 92 | + assert bugs[0].id == 1 |
| 93 | + assert bugs[0].whiteboard == "AV:N/AC:L/PR:H/UI:N/S:U/C:L/I:N/A:L" |
| 94 | + |
| 95 | + |
| 96 | +def test_get_bug_alias(mocked_responses, backends): |
| 97 | + bz = open_bz(url=TEST_URL, **backends) |
| 98 | + bug = bz.getbug("FOO-1") |
| 99 | + |
| 100 | + assert bug.id == 1 |
| 101 | + assert bug.summary == "ZeroDivisionError in function foo_bar()" |
0 commit comments