Ejemplo n.º 1
0
    def _create_patch(self, patch_contents):
        # FIXME: This code is brittle if the Attachment API changes.
        attachment = Attachment({"bug_id": 12345}, None)
        attachment.contents = lambda: patch_contents

        joe_cool = Committer(name="Joe Cool", email_or_emails=None)
        attachment.reviewer = lambda: joe_cool

        return attachment
Ejemplo n.º 2
0
    def _create_patch(self, patch_contents):
        # FIXME: This code is brittle if the Attachment API changes.
        attachment = Attachment({"bug_id": 12345}, None)
        attachment.contents = lambda: patch_contents

        joe_cool = Committer(name="Joe Cool", email_or_emails=None)
        attachment.reviewer = lambda: joe_cool

        return attachment
Ejemplo n.º 3
0
    def _create_patch(self, patch_contents):
        patch_path = os.path.join(self.svn_checkout_path, 'patch.diff')
        write_into_file_at_path(patch_path, patch_contents)
        patch = {}
        patch['bug_id'] = '12345'
        patch['url'] = 'file://%s' % urllib.pathname2url(patch_path)

        attachment = Attachment(patch, None) # FIXME: This is a hack, scm.py shouldn't be fetching attachment data.
        joe_cool = Committer(name="Joe Cool", email_or_emails=None)
        attachment._reviewer = joe_cool

        return attachment
Ejemplo n.º 4
0
 def _next_patch(self):
     patch_id = self._tool.status_server.next_work_item(self.name)
     if not patch_id:
         return None
     patch = self._tool.bugs.fetch_attachment(patch_id)
     if not patch:
         # FIXME: Using a fake patch because release_work_item has the wrong API.
         # We also don't really need to release the lock (although that's fine),
         # mostly we just need to remove this bogus patch from our queue.
         # If for some reason bugzilla is just down, then it will be re-fed later.
         patch = Attachment({'id': patch_id}, None)
         self._release_work_item(patch)
         return None
     return patch
Ejemplo n.º 5
0
    def refetch_patch(self, patch):
        if not self._reject_patch:
            return self._tool.bugs.fetch_attachment(patch.id())

        attachment_dictionary = {
            "id": patch.id(),
            "bug_id": patch.bug_id(),
            "name": "Rejected",
            "is_obsolete": True,
            "is_patch": False,
            "review": "-",
            "reviewer_email": "*****@*****.**",
            "commit-queue": "-",
            "committer_email": "*****@*****.**",
            "attacher_email": "Contributer1",
        }
        return Attachment(attachment_dictionary, None)
Ejemplo n.º 6
0
 def _next_patch(self):
     # FIXME: Bugzilla accessibility should be checked here; if it's unaccessible,
     # it should return None.
     patch = None
     while not patch:
         patch_id = self._tool.status_server.next_work_item(self.name)
         if not patch_id:
             return None
         try:
             patch = self._tool.bugs.fetch_attachment(patch_id, throw_on_access_error=True)
         except Bugzilla.AccessError as e:
             if e.error_code == Bugzilla.AccessError.NOT_PERMITTED:
                 patch = self._tool.status_server.fetch_attachment(patch_id)
         if not patch:
             # FIXME: Using a fake patch because release_work_item has the wrong API.
             # We also don't really need to release the lock (although that's fine),
             # mostly we just need to remove this bogus patch from our queue.
             # If for some reason bugzilla is just down, then it will be re-fed later.
             fake_patch = Attachment({'id': patch_id}, None)
             self._did_skip(fake_patch)
     return patch
Ejemplo n.º 7
0
class QueuesTest(unittest.TestCase):
    mock_work_item = Attachment(
        {
            "id": 1234,
            "bug_id": 345,
            "name": "Patch",
            "attacher_email": "*****@*****.**",
        }, None)

    def assert_queue_outputs(self,
                             queue,
                             args=None,
                             work_item=None,
                             expected_stdout=None,
                             expected_stderr=None,
                             options=Mock(),
                             tool=MockTool()):
        if not expected_stdout:
            expected_stdout = {}
        if not expected_stderr:
            expected_stderr = {}
        if not args:
            args = []
        if not work_item:
            work_item = self.mock_work_item
        tool.user.prompt = lambda message: "yes"

        queue.execute(options, args, tool, engine=MockQueueEngine)

        OutputCapture().assert_outputs(
            self,
            queue.queue_log_path,
            expected_stdout=expected_stdout.get("queue_log_path", ""),
            expected_stderr=expected_stderr.get("queue_log_path", ""))
        OutputCapture().assert_outputs(
            self,
            queue.work_item_log_path,
            args=[work_item],
            expected_stdout=expected_stdout.get("work_item_log_path", ""),
            expected_stderr=expected_stderr.get("work_item_log_path", ""))
        OutputCapture().assert_outputs(
            self,
            queue.begin_work_queue,
            expected_stdout=expected_stdout.get("begin_work_queue", ""),
            expected_stderr=expected_stderr.get("begin_work_queue", ""))
        OutputCapture().assert_outputs(
            self,
            queue.should_continue_work_queue,
            expected_stdout=expected_stdout.get("should_continue_work_queue",
                                                ""),
            expected_stderr=expected_stderr.get("should_continue_work_queue",
                                                ""))
        OutputCapture().assert_outputs(
            self,
            queue.next_work_item,
            expected_stdout=expected_stdout.get("next_work_item", ""),
            expected_stderr=expected_stderr.get("next_work_item", ""))
        OutputCapture().assert_outputs(self,
                                       queue.should_proceed_with_work_item,
                                       args=[work_item],
                                       expected_stdout=expected_stdout.get(
                                           "should_proceed_with_work_item",
                                           ""),
                                       expected_stderr=expected_stderr.get(
                                           "should_proceed_with_work_item",
                                           ""))
        OutputCapture().assert_outputs(
            self,
            queue.process_work_item,
            args=[work_item],
            expected_stdout=expected_stdout.get("process_work_item", ""),
            expected_stderr=expected_stderr.get("process_work_item", ""))
        OutputCapture().assert_outputs(
            self,
            queue.handle_unexpected_error,
            args=[work_item, "Mock error message"],
            expected_stdout=expected_stdout.get("handle_unexpected_error", ""),
            expected_stderr=expected_stderr.get("handle_unexpected_error", ""))
Ejemplo n.º 8
0
class QueuesTest(unittest.TestCase):
    mock_work_item = Attachment(
        {
            "id": 1234,
            "bug_id": 345,
            "name": "Patch",
            "attacher_email": "*****@*****.**",
        }, None)

    def assert_outputs(self, func, func_name, args, expected_stdout,
                       expected_stderr, expected_exceptions):
        exception = None
        if expected_exceptions and func_name in expected_exceptions:
            exception = expected_exceptions[func_name]

        OutputCapture().assert_outputs(
            self,
            func,
            args=args,
            expected_stdout=expected_stdout.get(func_name, ""),
            expected_stderr=expected_stderr.get(func_name, ""),
            expected_exception=exception)

    def assert_queue_outputs(self,
                             queue,
                             args=None,
                             work_item=None,
                             expected_stdout=None,
                             expected_stderr=None,
                             expected_exceptions=None,
                             options=Mock(),
                             tool=MockTool()):
        if not expected_stdout:
            expected_stdout = {}
        if not expected_stderr:
            expected_stderr = {}
        if not args:
            args = []
        if not work_item:
            work_item = self.mock_work_item
        tool.user.prompt = lambda message: "yes"

        queue.execute(options, args, tool, engine=MockQueueEngine)

        self.assert_outputs(queue.queue_log_path, "queue_log_path", [],
                            expected_stdout, expected_stderr,
                            expected_exceptions)
        self.assert_outputs(queue.work_item_log_path, "work_item_log_path",
                            [work_item], expected_stdout, expected_stderr,
                            expected_exceptions)
        self.assert_outputs(queue.begin_work_queue, "begin_work_queue", [],
                            expected_stdout, expected_stderr,
                            expected_exceptions)
        self.assert_outputs(queue.should_continue_work_queue,
                            "should_continue_work_queue", [], expected_stdout,
                            expected_stderr, expected_exceptions)
        self.assert_outputs(queue.next_work_item, "next_work_item", [],
                            expected_stdout, expected_stderr,
                            expected_exceptions)
        self.assert_outputs(queue.should_proceed_with_work_item,
                            "should_proceed_with_work_item", [work_item],
                            expected_stdout, expected_stderr,
                            expected_exceptions)
        self.assert_outputs(queue.process_work_item, "process_work_item",
                            [work_item], expected_stdout, expected_stderr,
                            expected_exceptions)
        self.assert_outputs(queue.handle_unexpected_error,
                            "handle_unexpected_error",
                            [work_item, "Mock error message"], expected_stdout,
                            expected_stderr, expected_exceptions)
        self.assert_outputs(queue.handle_script_error, "handle_script_error", [
            tool, {
                "patch": MockPatch()
            },
            ScriptError(message="ScriptError error message",
                        script_args="MockErrorCommand")
        ], expected_stdout, expected_stderr, expected_exceptions)