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)
def test_handleUnpushedBranch_has_required_privileges(self): # Dealing with an unpushed branch is a special code path that # was not exercised by the full-script test. Ensure that it has # the database privileges that it requires. 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")) self.becomeDbUser('translationstobranch') exporter._handleUnpushedBranch(productseries) # _handleUnpushedBranch completes successfully. There are no # database changes still pending in the ORM that are going to # fail either. transaction.commit()
def test_handleUnpushedBranch_is_privileged_to_contact_team(self): # Notifying a branch owner that is a team can require other # database privileges. The script also has these privileges. exporter = ExportTranslationsToBranch(test_args=[]) exporter.logger = BufferLogger() productseries = self.factory.makeProductSeries() email = self.factory.getUniqueEmailAddress() team_member = self.factory.makePerson(email=email) branch_owner = self.factory.makeTeam() getUtility(ITeamMembershipSet).new(team_member, branch_owner, TeamMembershipStatus.APPROVED, branch_owner.teamowner) productseries.translations_branch = self.factory.makeBranch( owner=branch_owner) exporter._exportToBranch = FakeMethod(failure=NotBranchError("Ow")) self.becomeDbUser('translationstobranch') exporter._handleUnpushedBranch(productseries) # _handleUnpushedBranch completes successfully. There are no # database changes still pending in the ORM that are going to # fail either. transaction.commit()
def test_handleUnpushedBranch_is_privileged_to_contact_team(self): # Notifying a branch owner that is a team can require other # database privileges. The script also has these privileges. exporter = ExportTranslationsToBranch(test_args=[]) exporter.logger = BufferLogger() productseries = self.factory.makeProductSeries() email = self.factory.getUniqueEmailAddress() team_member = self.factory.makePerson(email=email) branch_owner = self.factory.makeTeam() getUtility(ITeamMembershipSet).new( team_member, branch_owner, TeamMembershipStatus.APPROVED, branch_owner.teamowner) productseries.translations_branch = self.factory.makeBranch( owner=branch_owner) exporter._exportToBranch = FakeMethod(failure=NotBranchError("Ow")) self.becomeDbUser('translationstobranch') exporter._handleUnpushedBranch(productseries) # _handleUnpushedBranch completes successfully. There are no # database changes still pending in the ORM that are going to # fail either. transaction.commit()