|
| 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 |
0 commit comments