def test_noModification(self): """When there are no modifications, no delta should be returned.""" merge_proposal = self.factory.makeBranchMergeProposal() old_merge_proposal = BranchMergeProposalDelta.snapshot(merge_proposal) delta = BranchMergeProposalDelta.construct(old_merge_proposal, merge_proposal) assert delta is None
def test_noModification(self): """When there are no modifications, no delta should be returned.""" merge_proposal = self.factory.makeBranchMergeProposal() old_merge_proposal = BranchMergeProposalDelta.snapshot(merge_proposal) delta = BranchMergeProposalDelta.construct( old_merge_proposal, merge_proposal) assert delta is None
def test_snapshot(self): """Test that the snapshot method produces a reasonable snapshot""" merge_proposal = self.factory.makeBranchMergeProposal() merge_proposal.commit_message = 'foo' merge_proposal.whiteboard = 'bar' snapshot = BranchMergeProposalDelta.snapshot(merge_proposal) self.assertEqual('foo', snapshot.commit_message) self.assertEqual('bar', snapshot.whiteboard)
def test_Modification(self): """When there are modifications, the delta reflects them.""" registrant = self.factory.makePerson( displayname='Baz Qux', email='*****@*****.**') merge_proposal = self.factory.makeBranchMergeProposal( registrant=registrant) old_merge_proposal = BranchMergeProposalDelta.snapshot(merge_proposal) merge_proposal.commit_message = 'Change foo into bar.' merge_proposal.description = 'Set the description.' merge_proposal.markAsMerged() delta = BranchMergeProposalDelta.construct( old_merge_proposal, merge_proposal) assert delta is not None self.assertEqual('Change foo into bar.', delta.commit_message) self.assertEqual('Set the description.', delta.description) self.assertEqual( {'old': BranchMergeProposalStatus.WORK_IN_PROGRESS, 'new': BranchMergeProposalStatus.MERGED}, delta.queue_status)
def test_Modification(self): """When there are modifications, the delta reflects them.""" registrant = self.factory.makePerson(displayname='Baz Qux', email='*****@*****.**') merge_proposal = self.factory.makeBranchMergeProposal( registrant=registrant) old_merge_proposal = BranchMergeProposalDelta.snapshot(merge_proposal) merge_proposal.commit_message = 'Change foo into bar.' merge_proposal.description = 'Set the description.' merge_proposal.markAsMerged() delta = BranchMergeProposalDelta.construct(old_merge_proposal, merge_proposal) assert delta is not None self.assertEqual('Change foo into bar.', delta.commit_message) self.assertEqual('Set the description.', delta.description) self.assertEqual( { 'old': BranchMergeProposalStatus.WORK_IN_PROGRESS, 'new': BranchMergeProposalStatus.MERGED }, delta.queue_status)
def test_monitor(self): """\ `monitor` observes changes to a given merge proposal and issues `ObjectModifiedEvent` events if there are any. """ merge_proposal = self.factory.makeBranchMergeProposal() with EventRecorder() as event_recorder: # No event is issued when nothing is changed. with BranchMergeProposalDelta.monitor(merge_proposal): pass # Don't make changes. self.assertEqual(0, len(event_recorder.events)) # When one or more properties (of interest to # BranchMergeProposalDelta) are changed, a single event is issued. with BranchMergeProposalDelta.monitor(merge_proposal): merge_proposal.commit_message = "foo" merge_proposal.whiteboard = "bar" self.assertEqual(1, len(event_recorder.events)) [event] = event_recorder.events self.assertIsInstance(event, ObjectModifiedEvent) self.assertEqual(merge_proposal, event.object) self.assertContentEqual(["commit_message", "whiteboard"], event.edited_fields)
def run(self): """See `IRunnableJob`.""" self.checkReady() if self.branch_merge_proposal.source_branch is not None: server_context = server(get_ro_server(), no_replace=True) else: # A no-op context manager. (This could be simplified with # contextlib.ExitStack from Python 3.3.) server_context = contextmanager(lambda: (None for _ in [None]))() # Update related bug links based on commits in the source branch. self.branch_merge_proposal.updateRelatedBugsFromSource() with server_context: with BranchMergeProposalDelta.monitor(self.branch_merge_proposal): PreviewDiff.fromBranchMergeProposal(self.branch_merge_proposal)
def test_monitor(self): """\ `monitor` observes changes to a given merge proposal and issues `ObjectModifiedEvent` events if there are any. """ merge_proposal = self.factory.makeBranchMergeProposal() with EventRecorder() as event_recorder: # No event is issued when nothing is changed. with BranchMergeProposalDelta.monitor(merge_proposal): pass # Don't make changes. self.assertEqual(0, len(event_recorder.events)) # When one or more properties (of interest to # BranchMergeProposalDelta) are changed, a single event is issued. with BranchMergeProposalDelta.monitor(merge_proposal): merge_proposal.commit_message = "foo" merge_proposal.whiteboard = "bar" self.assertEqual(1, len(event_recorder.events)) [event] = event_recorder.events self.assertIsInstance(event, ObjectModifiedEvent) self.assertEqual(merge_proposal, event.object) self.assertContentEqual( ["commit_message", "whiteboard"], event.edited_fields)
def run(self): """See `IRunnableJob`.""" self.checkReady() with server(get_ro_server(), no_replace=True): with BranchMergeProposalDelta.monitor(self.branch_merge_proposal): PreviewDiff.fromBranchMergeProposal(self.branch_merge_proposal)