예제 #1
0
def testBasic():
    data = {
        "bug_id": 123456,
        "status": "NEW",
        "assigned_to": "*****@*****.**",
        "component": "foo",
        "product": "bar",
        "short_desc": "some short desc",
        "cf_fixed_in": "nope",
        "fixed_in": "1.2.3.4",
        "devel_whiteboard": "some status value",
    }

    bug = Bug(bugzilla=rhbz, dict=data)

    def _assert_bug():
        assert hasattr(bug, "component") is True
        assert getattr(bug, "components") == ["foo"]
        assert getattr(bug, "product") == "bar"
        assert hasattr(bug, "short_desc") is True
        assert getattr(bug, "summary") == "some short desc"
        assert bool(getattr(bug, "cf_fixed_in")) is True
        assert getattr(bug, "fixed_in") == "1.2.3.4"
        assert bool(getattr(bug, "cf_devel_whiteboard")) is True
        assert getattr(bug, "devel_whiteboard") == "some status value"

    _assert_bug()

    assert str(bug) == "#123456 NEW        - [email protected] - some short desc"
    assert repr(bug).startswith("<Bug #123456")

    # This triggers some code in __getattr__
    dir(bug)

    # Test special pickle support
    if sys.version_info[0] >= 3:
        import io
        fd = io.BytesIO()
    else:
        import StringIO  # pylint: disable=import-error
        fd = StringIO.StringIO()

    pickle.dump(bug, fd)
    fd.seek(0)
    bug = pickle.load(fd)
    assert getattr(bug, "bugzilla") is None
    assert str(bug)
    assert repr(bug)
    bug.bugzilla = rhbz
    _assert_bug()
예제 #2
0
    def testBasic(self):
        data = {
            "bug_id": 123456,
            "status": "NEW",
            "assigned_to": "*****@*****.**",
            "component": "foo",
            "product": "bar",
            "short_desc": "some short desc",
            "cf_fixed_in": "nope",
            "fixed_in": "1.2.3.4",
            "devel_whiteboard": "some status value",
        }

        bug = Bug(bugzilla=self.bz, dict=data)

        def _assert_bug():
            self.assertEqual(hasattr(bug, "component"), True)
            self.assertEqual(getattr(bug, "components"), ["foo"])
            self.assertEqual(getattr(bug, "product"), "bar")
            self.assertEqual(hasattr(bug, "short_desc"), True)
            self.assertEqual(getattr(bug, "summary"), "some short desc")
            self.assertEqual(bool(getattr(bug, "cf_fixed_in")), True)
            self.assertEqual(getattr(bug, "fixed_in"), "1.2.3.4")
            self.assertEqual(bool(getattr(bug, "cf_devel_whiteboard")), True)
            self.assertEqual(getattr(bug, "devel_whiteboard"),
                             "some status value")

        _assert_bug()

        self.assertEqual(str(bug),
                         "#123456 NEW        - [email protected] - some short desc")
        self.assertTrue(repr(bug).startswith("<Bug #123456"))

        # This triggers some code in __getattr__
        dir(bug)

        # Test special pickle support
        if hasattr(sys.version_info, "major") and sys.version_info.major >= 3:
            from io import BytesIO
            fd = BytesIO()
        else:
            fd = StringIO()

        pickle.dump(bug, fd)
        fd.seek(0)
        bug = pickle.load(fd)
        self.assertEqual(getattr(bug, "bugzilla"), None)
        bug.bugzilla = self.bz
        _assert_bug()
예제 #3
0
    def testBasic(self):
        data = {
            "bug_id": 123456,
            "status": "NEW",
            "assigned_to": "*****@*****.**",
            "component": "foo",
            "product": "bar",
            "short_desc": "some short desc",
            "cf_fixed_in": "nope",
            "fixed_in": "1.2.3.4",
            "devel_whiteboard": "some status value",
        }

        bug = Bug(bugzilla=self.bz, dict=data)

        def _assert_bug():
            self.assertEqual(hasattr(bug, "component"), True)
            self.assertEqual(getattr(bug, "components"), ["foo"])
            self.assertEqual(getattr(bug, "product"), "bar")
            self.assertEqual(hasattr(bug, "short_desc"), True)
            self.assertEqual(getattr(bug, "summary"), "some short desc")
            self.assertEqual(bool(getattr(bug, "cf_fixed_in")), True)
            self.assertEqual(getattr(bug, "fixed_in"), "1.2.3.4")
            self.assertEqual(bool(getattr(bug, "cf_devel_whiteboard")), True)
            self.assertEqual(getattr(bug, "devel_whiteboard"),
                "some status value")

        _assert_bug()

        self.assertEqual(str(bug),
            "#123456 NEW        - [email protected] - some short desc")
        self.assertTrue(repr(bug).startswith("<Bug #123456"))

        # This triggers some code in __getattr__
        dir(bug)

        # Test special pickle support
        if hasattr(sys.version_info, "major") and sys.version_info.major >= 3:
            from io import BytesIO
            fd = BytesIO()
        else:
            fd = StringIO()

        pickle.dump(bug, fd)
        fd.seek(0)
        bug = pickle.load(fd)
        self.assertEqual(getattr(bug, "bugzilla"), None)
        bug.bugzilla = self.bz
        _assert_bug()
예제 #4
0
    def testBasic(self):
        data = {
            "bug_id": 123456,
            "status": "NEW",
            "assigned_to": "*****@*****.**",
            "component": "foo",
            "product": "bar",
            "short_desc": "some short desc",
            "cf_fixed_in": "nope",
            "fixed_in": "1.2.3.4",
            "devel_whiteboard": "some status value",
        }

        bug = Bug(bugzilla=self.bz, dict=data)

        def _assert_bug():
            assert hasattr(bug, "component") is True
            assert getattr(bug, "components") == ["foo"]
            assert getattr(bug, "product") == "bar"
            assert hasattr(bug, "short_desc") is True
            assert getattr(bug, "summary") == "some short desc"
            assert bool(getattr(bug, "cf_fixed_in")) is True
            assert getattr(bug, "fixed_in") == "1.2.3.4"
            assert bool(getattr(bug, "cf_devel_whiteboard")) is True
            assert getattr(bug, "devel_whiteboard") == "some status value"

        _assert_bug()

        assert str(bug) == "#123456 NEW        - [email protected] - some short desc"
        assert repr(bug).startswith("<Bug #123456")

        # This triggers some code in __getattr__
        dir(bug)

        # Test special pickle support
        if sys.version_info[0] >= 3:
            from io import BytesIO
            fd = BytesIO()
        else:
            fd = StringIO()

        pickle.dump(bug, fd)
        fd.seek(0)
        bug = pickle.load(fd)
        assert getattr(bug, "bugzilla") is None
        bug.bugzilla = self.bz
        _assert_bug()
예제 #5
0
def search(payload):
    """
    Send a payload to the Bug.search RPC, and translate the result into
    bugzilla.bug.Bug results.
    """
    result = bzapi._proxy.Bug.search(payload)
    bugs = [Bug(bzapi, dict=r) for r in result['bugs']]
    return bugs
예제 #6
0
파일: bz.py 프로젝트: ktdreyer/rhcephbugs
def search(payload):
    """
    Send a payload to the Bug.search RPC, and translate the result into
    bugzilla.bug.Bug results.

    :param dict payload: A payload to search. Warning: this method mutates
                         this dict, adding "limit" and "offset" parameters.
    """
    bzapi = connect()
    result = bzapi._proxy.Bug.search(payload)
    bugs = [Bug(bzapi, dict=r) for r in result['bugs']]
    total_matches = result['total_matches']
    payload['limit'] = result['limit']
    payload['offset'] = result['offset']
    while len(bugs) < total_matches:
        payload['offset'] += result['limit']
        result = bzapi._proxy.Bug.search(payload)
        more_bugs = [Bug(bzapi, dict=r) for r in result['bugs']]
        bugs.extend(more_bugs)
    return bugs
예제 #7
0
    def preprocess_bug(self, bug: Bug) -> Optional[Dict[str, Any]]:
        """
        Process the bug instance and return
        dictionary with fields required by lower logic.

        Returns `None` if there are missing fields.
        """

        required_fields = [
            "bug_id",
            "creation_time",
            "last_change_time",
            "product",
            "version",
            "component",
            "summary",
            "status",
            "resolution",
            "cc",
            "status_whiteboard",
            "reporter",
            "groups",
        ]

        if self.save_comments:
            required_fields.append("comments")
        if self.save_attachments:
            required_fields.append("attachments")

        bug_dict = dict()
        for field in required_fields:
            if not hasattr(bug, field):
                self.log_error("Missing bug field {0}".format(field))
                return None

            bug_dict[field] = getattr(bug, field)

        for field in ["creation_time", "last_change_time"]:
            bug_dict[field] = self._convert_datetime(bug_dict[field])

        history = bug.get_history_raw()
        bug_dict["history"] = history["bugs"][0]["history"]
        if bug.resolution == "DUPLICATE":
            bug_dict["dupe_id"] = bug.dupe_id

        return bug_dict
def __bug(bz_handler):
    data = {
        "bug_id": 123456,
        "external_bugs": [],
        "keywords": "vkeyword",
        "assigned_to": "vassigned_to",
        "depends_on_all": [],
        "fixed_in": "",
        "status": "NEW",
        "assigned_to": "*****@*****.**",
        "component": "foo",
        "product": "bar",
        "short_desc": "some short desc",
        "cf_fixed_in": "nope",
        "fixed_in": "1.2.3.4",
        "devel_whiteboard": "some status value",
        "target_release": "---",
    }

    return [Bug(bugzilla=bz_handler, dict=data)]
예제 #9
0
 def testBugNoID(self):
     try:
         Bug(bugzilla=self.bz, dict={"component": "foo"})
         raise AssertionError("Expected lack of ID failure.")
     except TypeError:
         pass