def test_bug_497141(self):
        # Regression test for bug 497141. KeyErrors raised in
        # RemoteBugUpdater.updateRemoteBug() shouldn't cause
        # checkwatches to abort.
        (bug_tracker, bug_watches) = self.factory.makeBugTrackerWithWatches()

        # Use a test XML-RPC transport to ensure no connections happen.
        test_transport = TestBugzillaAPIXMLRPCTransport(bug_tracker.baseurl)
        remote_system = NonConnectingBugzillaAPI(
            bug_tracker.baseurl, xmlrpc_transport=test_transport)

        working_base = WorkingBase()
        working_base.init(LOGIN, transaction.manager, BufferLogger())

        for bug_watch in bug_watches:
            # we want to know that an oops was raised
            oops_count = len(self.oopses)
            updater = NoBugWatchesByRemoteBugUpdater(
                working_base, remote_system, bug_watch.remotebug,
                [bug_watch.id], [], datetime.now())

            # Calling updateRemoteBug() shouldn't raise a KeyError,
            # even though with our broken updater
            # _getExternalBugTrackersAndWatches() will return an empty
            # dict.
            updater.updateRemoteBug()

            # A single oops will have been logged instead of the KeyError
            # being raised.
            self.assertEqual(oops_count + 1, len(self.oopses))
            last_oops = self.oopses[-1]
            self.assertStartsWith(
                last_oops['value'], 'Spurious remote bug ID')
Exemple #2
0
 def test_transaction_with_open_transaction(self):
     # On entry, WorkingBase.transaction will raise an exception if
     # a transaction is in progress.
     transaction_manager = StubTransactionManager()
     base = WorkingBase()
     base.init(self.email, transaction_manager, self.logger)
     self.assertTrue(is_transaction_in_progress())
     self.assertRaises(TransactionInProgress, base.transaction.__enter__)
 def test_transaction_with_open_transaction(self):
     # On entry, WorkingBase.transaction will raise an exception if
     # a transaction is in progress.
     transaction_manager = StubTransactionManager()
     base = WorkingBase()
     base.init(self.email, transaction_manager, self.logger)
     self.assertTrue(is_transaction_in_progress())
     self.assertRaises(TransactionInProgress, base.transaction.__enter__)
 def test_interaction(self):
     # The WorkingBase.interaction context manager will begin an
     # interaction on entry and end it on exit.
     base = WorkingBase()
     base.init(self.email, transaction.manager, self.logger)
     endInteraction()
     self.assertIs(None, queryInteraction())
     with base.interaction:
         self.assertIsNot(None, queryInteraction())
     self.assertIs(None, queryInteraction())
Exemple #5
0
 def test_interaction(self):
     # The WorkingBase.interaction context manager will begin an
     # interaction on entry and end it on exit.
     base = WorkingBase()
     base.init(self.email, transaction.manager, self.logger)
     endInteraction()
     self.assertIs(None, queryInteraction())
     with base.interaction:
         self.assertIsNot(None, queryInteraction())
     self.assertIs(None, queryInteraction())
 def _test_sql_log_cleared_after_x(self):
     person = self.factory.makePerson()
     email = person.preferredemail.email
     logger = BufferLogger()
     base = WorkingBase()
     base.init(email, transaction.manager, logger)
     with base.statement_logging:
         self.factory.makeEmail("*****@*****.**", person)
         self.assertTrue(len(get_request_statements()) > 0, "We need at least one statement in the SQL log.")
         yield base
         self.assertTrue(
             len(get_request_statements()) == 0, "SQL statement log not cleared by WorkingBase.warning()."
         )
Exemple #7
0
 def test_interaction_nested(self):
     # If an interaction is already in progress, the interaction
     # context manager will not begin a new interaction on entry,
     # nor will it end the interaction on exit.
     base = WorkingBase()
     base.init(self.email, transaction.manager, self.logger)
     endInteraction()
     self.assertIs(None, queryInteraction())
     with base.interaction:
         self.assertIsNot(None, queryInteraction())
         with base.interaction:
             self.assertIsNot(None, queryInteraction())
         self.assertIsNot(None, queryInteraction())
     self.assertIs(None, queryInteraction())
 def test_interaction_nested(self):
     # If an interaction is already in progress, the interaction
     # context manager will not begin a new interaction on entry,
     # nor will it end the interaction on exit.
     base = WorkingBase()
     base.init(self.email, transaction.manager, self.logger)
     endInteraction()
     self.assertIs(None, queryInteraction())
     with base.interaction:
         self.assertIsNot(None, queryInteraction())
         with base.interaction:
             self.assertIsNot(None, queryInteraction())
         self.assertIsNot(None, queryInteraction())
     self.assertIs(None, queryInteraction())
Exemple #9
0
 def _test_sql_log_cleared_after_x(self):
     person = self.factory.makePerson()
     email = person.preferredemail.email
     logger = BufferLogger()
     base = WorkingBase()
     base.init(email, transaction.manager, logger)
     with base.statement_logging:
         self.factory.makeEmail('*****@*****.**', person)
         self.assertTrue(
             len(get_request_statements()) > 0,
             "We need at least one statement in the SQL log.")
         yield base
         self.assertTrue(
             len(get_request_statements()) == 0,
             "SQL statement log not cleared by WorkingBase.warning().")
Exemple #10
0
 def test_transaction(self):
     # The WonkingBase.transaction context manager ensures that no
     # transaction is in progress on entry, commits on a successful
     # exit, or aborts the transaction on failure.
     transaction_manager = StubTransactionManager()
     base = WorkingBase()
     base.init(self.email, transaction_manager, self.logger)
     transaction.commit()
     with base.transaction:
         self.assertFalse(is_transaction_in_progress())
         self.assertEqual([], transaction_manager.log)
         self.factory.makeEmail('*****@*****.**', self.person)
         self.assertTrue(is_transaction_in_progress())
         self.assertEqual([], transaction_manager.log)
     self.assertEqual(['commit'], transaction_manager.log)
Exemple #11
0
 def test_transaction(self):
     # The WonkingBase.transaction context manager ensures that no
     # transaction is in progress on entry, commits on a successful
     # exit, or aborts the transaction on failure.
     transaction_manager = StubTransactionManager()
     base = WorkingBase()
     base.init(self.email, transaction_manager, self.logger)
     transaction.commit()
     with base.transaction:
         self.assertFalse(is_transaction_in_progress())
         self.assertEqual([], transaction_manager.log)
         self.factory.makeEmail("*****@*****.**", self.person)
         self.assertTrue(is_transaction_in_progress())
         self.assertEqual([], transaction_manager.log)
     self.assertEqual(["commit"], transaction_manager.log)
Exemple #12
0
 def test_transaction_with_exception(self):
     # If an exception is raised when the transaction context
     # manager is active, the transaction will be aborted and the
     # exception re-raised.
     transaction_manager = StubTransactionManager()
     base = WorkingBase()
     base.init(self.email, transaction_manager, self.logger)
     transaction.commit()
     try:
         with base.transaction:
             raise RuntimeError("Nothing really.")
     except RuntimeError:
         self.assertFalse(is_transaction_in_progress())
         self.assertEqual(["abort"], transaction_manager.log)
     else:
         self.fail("Exception not re-raised from context manager.")
Exemple #13
0
 def test_transaction_with_exception(self):
     # If an exception is raised when the transaction context
     # manager is active, the transaction will be aborted and the
     # exception re-raised.
     transaction_manager = StubTransactionManager()
     base = WorkingBase()
     base.init(self.email, transaction_manager, self.logger)
     transaction.commit()
     try:
         with base.transaction:
             raise RuntimeError("Nothing really.")
     except RuntimeError:
         self.assertFalse(is_transaction_in_progress())
         self.assertEqual(['abort'], transaction_manager.log)
     else:
         self.fail("Exception not re-raised from context manager.")
Exemple #14
0
 def test_statement_logging(self):
     # The WorkingBase.statement_logging context manager starts
     # statement logging on entry and stops it on exit.
     base = WorkingBase()
     base.init(self.email, transaction.manager, self.logger)
     self.factory.makeEmail("*****@*****.**", self.person)
     self.assertEqual(
         0, len(get_request_statements()), "The statement log should be empty because " "logging is not enabled."
     )
     with base.statement_logging:
         self.assertEqual(0, len(get_request_statements()), "There should be no statements in the log yet.")
         self.factory.makeEmail("*****@*****.**", self.person)
         self.assertTrue(len(get_request_statements()) > 0, "There should be at least one statement in the log.")
     self.assertEqual(
         0, len(get_request_statements()), "SQL statement log not cleared on exit " "from base.statement_logging."
     )
Exemple #15
0
 def test_statement_logging(self):
     # The WorkingBase.statement_logging context manager starts
     # statement logging on entry and stops it on exit.
     base = WorkingBase()
     base.init(self.email, transaction.manager, self.logger)
     self.factory.makeEmail('*****@*****.**', self.person)
     self.assertEqual(
         0, len(get_request_statements()),
         "The statement log should be empty because "
         "logging is not enabled.")
     with base.statement_logging:
         self.assertEqual(0, len(get_request_statements()),
                          "There should be no statements in the log yet.")
         self.factory.makeEmail('*****@*****.**', self.person)
         self.assertTrue(
             len(get_request_statements()) > 0,
             "There should be at least one statement in the log.")
     self.assertEqual(
         0, len(get_request_statements()),
         "SQL statement log not cleared on exit "
         "from base.statement_logging.")
Exemple #16
0
 def test_initFromParent(self):
     base1 = WorkingBase()
     base1.init(self.email, transaction.manager, self.logger)
     base2 = WorkingBase()
     base2.initFromParent(base1)
     self.failUnlessEqual(base1.__dict__, base2.__dict__)
Exemple #17
0
 def test_initFromParent(self):
     base1 = WorkingBase()
     base1.init(self.email, transaction.manager, self.logger)
     base2 = WorkingBase()
     base2.initFromParent(base1)
     self.assertEqual(base1.__dict__, base2.__dict__)