Example #1
0
    def test_record_creates_notification(self,
                                         discord_execute,
                                         hipchat_execute,
                                         pagerduty_execute,
                                         mattermost_execute,
                                         slack_execute,
                                         webhook_execute,
                                         email_execute):
        notification_events = NotificationEvent.objects.count()
        notifications = Notification.objects.count()

        notifier.record(event_type=EXPERIMENT_SUCCEEDED,
                        instance=self.experiment)

        assert discord_execute.call_count == 1
        assert hipchat_execute.call_count == 1
        assert pagerduty_execute.call_count == 1
        assert mattermost_execute.call_count == 1
        assert slack_execute.call_count == 1
        assert webhook_execute.call_count == 1
        assert email_execute.call_count == 1

        assert NotificationEvent.objects.count() == notification_events + 1
        assert Notification.objects.count() == notifications + 2
        notification_event = NotificationEvent.objects.last()
        notifications = Notification.objects.all()
        assert notification_event.event_type == EXPERIMENT_SUCCEEDED
        assert notification_event.content_object == self.experiment
        assert set(notifications.values_list('user__id', flat=True)) == {
            self.experiment.user.id, self.experiment.project.user.id}
Example #2
0
    def test_record_does_not_create_notification_for_non_tracked_events(
            self, discord_execute, hipchat_execute, pagerduty_execute,
            mattermost_execute, slack_execute, webhook_execute, email_execute):
        notification_events = NotificationEvent.objects.count()
        notifications = Notification.objects.count()

        notifier.record(event_type=EXPERIMENT_VIEWED, instance=self.experiment)

        assert discord_execute.call_count == 0
        assert hipchat_execute.call_count == 0
        assert pagerduty_execute.call_count == 0
        assert mattermost_execute.call_count == 0
        assert slack_execute.call_count == 0
        assert webhook_execute.call_count == 0
        assert email_execute.call_count == 0

        assert NotificationEvent.objects.count() == notification_events
        assert Notification.objects.count() == notifications