예제 #1
0
 def test_restores_observers(self):
     from testtools.deferredruntest import run_with_log_observers
     from twisted.python import log
     # Make sure there's at least one observer.  This reproduces bug
     # #926189.
     log.addObserver(lambda *args: None)
     observers = list(log.theLogPublisher.observers)
     run_with_log_observers([], lambda: None)
     self.assertEqual(observers, log.theLogPublisher.observers)
예제 #2
0
 def test_restores_observers(self):
     from testtools.deferredruntest import run_with_log_observers
     from twisted.python import log
     # Make sure there's at least one observer.  This reproduces bug
     # #926189.
     log.addObserver(lambda *args: None)
     observers = list(log.theLogPublisher.observers)
     run_with_log_observers([], lambda: None)
     self.assertEqual(observers, log.theLogPublisher.observers)
예제 #3
0
 def test_render_error(self):
     """
     L{FrontEndAjax.render} displays an error if C{get_message} raises an
     exception.
     """
     self.message_queue.messages["uuid1"] = ValueError("Not there")
     request = FakeRequest({"uuid": ["uuid1"], "sequence": ["0"]})
     run_with_log_observers([], self.ajax.render, request)
     self.assertEquals(request.written.getvalue(), "Not there")
     self.assertEquals(request.code, 500)
예제 #4
0
    def test_branchChanged_stderr_text(self):
        # An unexpected error invoking branchChanged() results in a user
        # friendly error printed to stderr (and not a traceback).

        # Unlocking a branch calls branchChanged x 2 on the branch filesystem
        # endpoint. We will then check the error handling.
        db_branch = self.factory.makeAnyBranch(branch_type=BranchType.HOSTED,
                                               owner=self.requester)
        branch = run_with_log_observers([], self.make_branch,
                                        db_branch.unique_name)
        branch.lock_write()
        branch.unlock()
        stderr_text = sys.stderr.getvalue()

        # The text printed to stderr should be like this:
        # (we need the prefix text later for extracting the oopsid)
        expected_fault_text_prefix = """
        <Fault 380: 'An unexpected error has occurred while updating a
        Launchpad branch. Please report a Launchpad bug and quote:"""
        expected_fault_text = expected_fault_text_prefix + " OOPS-.*'>"

        # For our test case, branchChanged() is called twice, hence 2 errors.
        expected_stderr = ' '.join([expected_fault_text for x in range(2)])
        self.assertTextMatchesExpressionIgnoreWhitespace(
            expected_stderr, stderr_text)

        # Extract an oops id from the std error text.
        # There will be 2 oops ids. The 2nd will be the oops for the last
        # logged error report and the 1st will be in the error text from the
        # error report.
        oopsids = []
        stderr_text = ' '.join(stderr_text.split())
        expected_fault_text_prefix = ' '.join(
            expected_fault_text_prefix.split())
        parts = re.split(expected_fault_text_prefix, stderr_text)
        for txt in parts:
            if len(txt) == 0:
                continue
            txt = txt.strip()
            # The oopsid ends with a '.'
            oopsid = txt[:txt.find('.')]
            oopsids.append(oopsid)

        # Now check the error report - we just check the last one.
        self.assertEqual(len(oopsids), 2)
        error_report = self.oopses[-1]
        # The error report oopsid should match what's print to stderr.
        self.assertEqual(error_report['id'], oopsids[1])
        # The error report text should contain the root cause oopsid.
        self.assertContainsString(error_report['tb_text'],
                                  self.generated_oopsids[1])
예제 #5
0
    def test_branchChanged_stderr_text(self):
        # An unexpected error invoking branchChanged() results in a user
        # friendly error printed to stderr (and not a traceback).

        # Unlocking a branch calls branchChanged x 2 on the branch filesystem
        # endpoint. We will then check the error handling.
        db_branch = self.factory.makeAnyBranch(
            branch_type=BranchType.HOSTED, owner=self.requester)
        branch = run_with_log_observers(
            [], self.make_branch, db_branch.unique_name)
        branch.lock_write()
        branch.unlock()
        stderr_text = sys.stderr.getvalue()

        # The text printed to stderr should be like this:
        # (we need the prefix text later for extracting the oopsid)
        expected_fault_text_prefix = """
        <Fault 380: 'An unexpected error has occurred while updating a
        Launchpad branch. Please report a Launchpad bug and quote:"""
        expected_fault_text = expected_fault_text_prefix + " OOPS-.*'>"

        # For our test case, branchChanged() is called twice, hence 2 errors.
        expected_stderr = ' '.join([expected_fault_text for x in range(2)])
        self.assertTextMatchesExpressionIgnoreWhitespace(
            expected_stderr, stderr_text)

        # Extract an oops id from the std error text.
        # There will be 2 oops ids. The 2nd will be the oops for the last
        # logged error report and the 1st will be in the error text from the
        # error report.
        oopsids = []
        stderr_text = ' '.join(stderr_text.split())
        expected_fault_text_prefix = ' '.join(
            expected_fault_text_prefix.split())
        parts = re.split(expected_fault_text_prefix, stderr_text)
        for txt in parts:
            if len(txt) == 0:
                continue
            txt = txt.strip()
            # The oopsid ends with a '.'
            oopsid = txt[:txt.find('.')]
            oopsids.append(oopsid)

        # Now check the error report - we just check the last one.
        self.assertEqual(len(oopsids), 2)
        error_report = self.oopses[-1]
        # The error report oopsid should match what's print to stderr.
        self.assertEqual(error_report['id'], oopsids[1])
        # The error report text should contain the root cause oopsid.
        self.assertContainsString(
            error_report['tb_text'], self.generated_oopsids[1])