def test_handleUnpushedBranch_mails_branch_owner(self): exporter = ExportTranslationsToBranch(test_args=[]) exporter.logger = BufferLogger() productseries = self.factory.makeProductSeries() email = self.factory.getUniqueEmailAddress() branch_owner = self.factory.makePerson(email=email) productseries.translations_branch = self.factory.makeBranch( owner=branch_owner) exporter._exportToBranch = FakeMethod(failure=NotBranchError("Ow")) exporter._sendMail = FakeMethod() self.becomeDbUser('translationstobranch') exporter._exportToBranches([productseries]) self.assertEqual(1, exporter._sendMail.call_count) (sender, recipients, subject, text), kwargs = (exporter._sendMail.calls[-1]) self.assertIn(config.canonical.noreply_from_address, sender) self.assertIn(email, recipients) self.assertEqual("Launchpad: translations branch has not been set up.", subject) self.assertIn("problem with translations branch synchronization", text) self.assertIn(productseries.title, text) self.assertIn(productseries.translations_branch.bzr_identity, text) self.assertIn('bzr push lp://', text)
def test_handleUnpushedBranch_mails_branch_owner(self): exporter = ExportTranslationsToBranch(test_args=[]) exporter.logger = BufferLogger() productseries = self.factory.makeProductSeries() email = self.factory.getUniqueEmailAddress() branch_owner = self.factory.makePerson(email=email) productseries.translations_branch = self.factory.makeBranch( owner=branch_owner) exporter._exportToBranch = FakeMethod(failure=NotBranchError("Ow")) exporter._sendMail = FakeMethod() self.becomeDbUser('translationstobranch') exporter._exportToBranches([productseries]) self.assertEqual(1, exporter._sendMail.call_count) (sender, recipients, subject, text), kwargs = ( exporter._sendMail.calls[-1]) self.assertIn(config.canonical.noreply_from_address, sender) self.assertIn(email, recipients) self.assertEqual( "Launchpad: translations branch has not been set up.", subject) self.assertIn( "problem with translations branch synchronization", text) self.assertIn(productseries.title, text) self.assertIn(productseries.translations_branch.bzr_identity, text) self.assertIn('bzr push lp://', text)
def test_exportToBranches_handles_nonascii_exceptions(self): # There's an exception handler in _exportToBranches that must # cope well with non-ASCII exception strings. productseries = self.factory.makeProductSeries() exporter = ExportTranslationsToBranch(test_args=[]) exporter.logger = BufferLogger() boom = u'\u2639' exporter._exportToBranch = FakeMethod(failure=GruesomeException(boom)) self.becomeDbUser('translationstobranch') exporter._exportToBranches([productseries]) self.assertEqual(1, exporter._exportToBranch.call_count) message = exporter.logger.getLogBuffer() self.assertTrue(message.startswith("ERROR")) self.assertTrue("GruesomeException" in message)
def test_exportToBranches_handles_unpushed_branches(self): # bzrlib raises NotBranchError when accessing a nonexistent # branch. The exporter deals with that by calling # _handleUnpushedBranch. exporter = ExportTranslationsToBranch(test_args=[]) exporter.logger = BufferLogger() productseries = self.factory.makeProductSeries() productseries.translations_branch = self.factory.makeBranch() self.becomeDbUser('translationstobranch') # _handleUnpushedBranch is called if _exportToBranch raises # NotBranchError. exporter._handleUnpushedBranch = FakeMethod() exporter._exportToBranch = FakeMethod(failure=NotBranchError("No!")) exporter._exportToBranches([productseries]) self.assertEqual(1, exporter._handleUnpushedBranch.call_count) # This does not happen if the export succeeds. exporter._handleUnpushedBranch = FakeMethod() exporter._exportToBranch = FakeMethod() exporter._exportToBranches([productseries]) self.assertEqual(0, exporter._handleUnpushedBranch.call_count) # Nor does it happen if the export fails in some other way. exporter._handleUnpushedBranch = FakeMethod() exporter._exportToBranch = FakeMethod(failure=IndexError("Ayyeee!")) exporter._exportToBranches([productseries]) self.assertEqual(0, exporter._handleUnpushedBranch.call_count)