def test_bugzilla_error_doesnt_create_notification(self): self.assertEqual(Notification.objects.count(), 0) self.mock_bugzilla_requests_post.side_effect = RequestException() tasks.create_experiment_bug_task(self.user.id, self.experiment.id) self.mock_bugzilla_requests_post.assert_called() self.assertEqual(Notification.objects.count(), 0) experiment = Experiment.objects.get(id=self.experiment.id) self.assertEqual(experiment.bugzilla_id, None)
def test_bugzilla_error_creates_error_notification(self): self.assertEqual(Notification.objects.count(), 0) self.mock_bugzilla_requests_post.side_effect = RequestException() with self.assertRaises(bugzilla.BugzillaError): with MetricsMock() as mm: tasks.create_experiment_bug_task(self.user.id, self.experiment.id) self.assertTrue( mm.has_record( markus.INCR, "experiments.tasks.create_experiment_bug.started", value=1, ) ) self.assertTrue( mm.has_record( markus.INCR, "experiments.tasks.create_experiment_bug.failed", value=1, ) ) # Failures should abort timing metrics. self.assertFalse( mm.has_record( markus.TIMING, "experiments.tasks.create_experiment_bug.timing" ) ) # Completed metric should not be sent. self.assertFalse( mm.has_record( markus.INCR, "experiments.tasks.create_experiment_bug.completed" ) ) self.mock_bugzilla_requests_post.assert_called() self.assertEqual(Notification.objects.count(), 1) experiment = Experiment.objects.get(id=self.experiment.id) self.assertEqual(experiment.bugzilla_id, None) notification = Notification.objects.get() self.assertEqual(notification.user, self.user) self.assertEqual( notification.message, tasks.NOTIFICATION_MESSAGE_CREATE_BUG_FAILED )
def test_experiment_bug_successfully_created(self): self.assertEqual(Notification.objects.count(), 0) tasks.create_experiment_bug_task(self.user.id, self.experiment.id) self.mock_bugzilla_requests_post.assert_called() experiment = Experiment.objects.get(id=self.experiment.id) self.assertEqual(experiment.bugzilla_id, self.bugzilla_id) notification = Notification.objects.get() self.assertEqual(notification.user, self.user) self.assertEqual( notification.message, tasks.NOTIFICATION_MESSAGE_CREATE_BUG.format( bug_url=experiment.bugzilla_url), )
def test_bugzilla_error_creates_error_notification(self): self.assertEqual(Notification.objects.count(), 0) self.mock_bugzilla_requests_post.side_effect = RequestException() with self.assertRaises(bugzilla.BugzillaError): tasks.create_experiment_bug_task(self.user.id, self.experiment.id) self.mock_bugzilla_requests_post.assert_called() self.assertEqual(Notification.objects.count(), 1) experiment = Experiment.objects.get(id=self.experiment.id) self.assertEqual(experiment.bugzilla_id, None) notification = Notification.objects.get() self.assertEqual(notification.user, self.user) self.assertEqual(notification.message, tasks.NOTIFICATION_MESSAGE_CREATE_BUG_FAILED)
def test_experiment_bug_successfully_created(self): self.assertEqual(Notification.objects.count(), 0) with MetricsMock() as mm: tasks.create_experiment_bug_task(self.user.id, self.experiment.id) self.assertTrue( mm.has_record( markus.INCR, "experiments.tasks.create_experiment_bug.started", value=1, ) ) self.assertTrue( mm.has_record( markus.INCR, "experiments.tasks.create_experiment_bug.completed", value=1, ) ) self.assertTrue( mm.has_record( markus.TIMING, "experiments.tasks.create_experiment_bug.timing" ) ) # Failed metric should not be sent. self.assertFalse( mm.has_record( markus.INCR, "experiments.tasks.create_experiment_bug.failed" ) ) self.mock_bugzilla_requests_post.assert_called() experiment = Experiment.objects.get(id=self.experiment.id) self.assertEqual(experiment.bugzilla_id, self.bugzilla_id) notification = Notification.objects.get() self.assertEqual(notification.user, self.user) self.assertEqual( notification.message, tasks.NOTIFICATION_MESSAGE_CREATE_BUG.format(bug_url=experiment.bugzilla_url), )