def test_cancel_draft_service_change_comments_on_jira_issue(self, mock_JIRA): # If we cancel a pending change to a current service, it adds a comment # to the existing jira issue. # make the service we're canceling look like a change to an existing service existing_service = ServiceFactory(status=Service.STATUS_CURRENT) draft_service = ServiceFactory( update_of=existing_service, status=Service.STATUS_DRAFT, ) # Pretend we've created a JIRA issue when the draft was started. issue_key = 'XXX-123' draft_service.jira_records.update(jira_issue_key=issue_key) # Now cancel the draft draft_service.cancel() # We should get a new jira update record created cancel_record = \ draft_service.jira_records.get(update_type=JiraUpdateRecord.CANCEL_DRAFT_SERVICE) # run it: cancel_record.do_jira_work() call_args, call_kwargs = mock_JIRA.return_value.add_comment.call_args # Only checking summary as that has the essentially different value # from what the "new service" case sets. self.assertEqual(issue_key, call_args[0]) self.assertIn('change was canceled', call_args[1]) record = JiraUpdateRecord.objects.get(pk=cancel_record.pk) self.assertEqual(issue_key, record.jira_issue_key) # We should NOT have created a new JIRA record self.assertFalse(mock_JIRA.return_value.create_issue.called)
def test_cancel_cleans_up_pending_changes(self): service1 = ServiceFactory(status=Service.STATUS_CURRENT) # Make copy of service1 as an update service2 = Service.objects.get(pk=service1.pk) service2.pk = None service2.update_of = service1 service2.status = Service.STATUS_DRAFT service2.save() service1.cancel() service2 = Service.objects.get(pk=service2.pk) self.assertEqual(Service.STATUS_CANCELED, service2.status)