def test_issue_update_callback_creates_deletes_two_comments(self): factories.CommentFactory(issue=self.issue) factories.CommentFactory(issue=self.issue) synchronizer = CommentSynchronizer(self.backend, self.issue, self.backend_issue) synchronizer.perform_update() self.assertEqual(self.issue.comments.count(), 0)
def setUp(self): jira_backend = 'waldur_mastermind.support.backend.atlassian:ServiceDeskBackend' settings.WALDUR_SUPPORT['ENABLED'] = True settings.WALDUR_SUPPORT['ACTIVE_BACKEND'] = jira_backend self.comment = factories.CommentFactory() backend_comment_raw = json.loads( load_resource('jira_comment_raw.json')) self.backend_comment = jira.resources.Comment( {'server': 'example.com'}, None, backend_comment_raw) self.backend = ServiceDeskBackend() self.internal = {'value': {'internal': False}} path = mock.patch.object( ServiceDeskBackend, '_get_property', new=mock.Mock(return_value=self.internal), ) path.start() path = mock.patch.object( ServiceDeskBackend, 'get_backend_comment', new=mock.Mock(return_value=self.backend_comment), ) path.start()
def test_expert(self): fixture = fixtures.ExpertsFixture() factories.ExpertBidFactory(request=self.expert_request, team=fixture.project) expert = fixture.manager support_factories.CommentFactory(issue=self.expert_request.issue, author__user=expert) self.assert_has_role(expert, 'expert')
def test_send_notification_for_expert_if_user_added_comment(self, send_mock): self.comment = support_factories.CommentFactory(issue=self.fixture.issue) self.fixture.contract self.fixture.expert_request self.fixture.admin serialized_comment = core_utils.serialize_instance(self.comment) tasks.send_expert_comment_added_notification(serialized_comment) self.assertEqual(send_mock.call_count, 1)
def test_email_is_not_sent_when_public_comment_is_updated(self): comment = factories.CommentFactory(is_public=True) self.assertEqual(len(mail.outbox), 1) comment.description = 'new_description' comment.save() # First mail is for creation, second mail is for update self.assertEqual(len(mail.outbox), 2)
def assert_has_role(self, user, role): support_factories.CommentFactory(issue=self.expert_request.issue, author__user=user) url = factories.ExpertRequestFactory.get_url(self.expert_request, 'users') self.client.force_login(self.expert_fixture.staff) response = self.client.get(url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(role in response.data[user.uuid.hex])
def test_issue_update_callback_updates_a_comment(self): # arrange backend_id, issue, _ = self.set_issue_and_support_user() expected_comment_body = 'Merry Christmas' comment = factories.CommentFactory(issue=issue) self.request_data['issue']['key'] = issue.backend_id self.request_data['issue']['fields']['reporter'][ 'key'] = issue.reporter.backend_id self.request_data['issue']['fields']['comment']['comments'][0][ 'id'] = comment.backend_id self.request_data['issue']['fields']['comment']['comments'][0][ 'body'] = expected_comment_body # act response = self.client.post(self.url, self.request_data) self.assertEqual(response.status_code, status.HTTP_200_OK) issue.refresh_from_db() issue_comment = issue.comments.first() self.assertIsNotNone(issue_comment) self.assertEqual(issue_comment.description, expected_comment_body)
def test_webhook_cleans_up_user_info_and_does_not_update_comment_if_it_is_not_changed( self): # arrange backend_id, issue, _ = self.set_issue_and_support_user() comment = factories.CommentFactory(issue=issue) expected_comment_body = comment.description jira_comment_body = '[Luke Skywalker 19BBY-TA-T16]: %s' % expected_comment_body self.request_data['issue']['key'] = issue.backend_id self.request_data['issue']['fields']['reporter'][ 'key'] = issue.reporter.backend_id self.request_data['issue']['fields']['comment']['comments'][0][ 'id'] = comment.backend_id self.request_data['issue']['fields']['comment']['comments'][0][ 'body'] = jira_comment_body # act response = self.client.post(self.url, self.request_data) self.assertEqual(response.status_code, status.HTTP_200_OK) issue.refresh_from_db() issue_comment = issue.comments.first() self.assertIsNotNone(issue_comment) self.assertEqual(issue_comment.description, expected_comment_body)
def test_email_is_not_sent_if_feature_is_suppressed(self): with self.settings(SUPPRESS_NOTIFICATION_EMAILS=True): factories.CommentFactory(is_public=True) self.assertEqual(len(mail.outbox), 0)
def test_email_is_not_sent_for_own_comments(self): issue = factories.IssueFactory() factories.CommentFactory(issue=issue, is_public=True, author__user=issue.caller) self.assertEqual(len(mail.outbox), 0)
def test_email_is_not_sent_for_private_comment(self): factories.CommentFactory() self.assertEqual(len(mail.outbox), 0)
def test_email_is_sent_when_public_comment_is_created(self): factories.CommentFactory(is_public=True) self.assertEqual(len(mail.outbox), 1)
def test_comment_delete(self, mock_jira): comment = factories.CommentFactory(issue=self.issue) self.request_data_comment_delete['comment']['id'] = comment.backend_id self.client.post(self.url, self.request_data_comment_delete) self.assertTrue(self._call_delete_comment(mock_jira))