mirror of
https://github.com/jlengrand/bugsink.git
synced 2026-03-10 08:01:17 +00:00
new-issue and regression alerts (not actually implemented, but the call is)
This commit is contained in:
@@ -2,5 +2,15 @@ from celery import shared_task
|
||||
|
||||
|
||||
@shared_task
|
||||
def send_unmute_notification(issue_id):
|
||||
def send_new_issue_alert(issue_id):
|
||||
raise NotImplementedError("TODO")
|
||||
|
||||
|
||||
@shared_task
|
||||
def send_regression_alert(issue_id):
|
||||
raise NotImplementedError("TODO")
|
||||
|
||||
|
||||
@shared_task
|
||||
def send_unmute_alert(issue_id):
|
||||
raise NotImplementedError("TODO")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import datetime
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
@@ -17,7 +18,9 @@ class IngestViewTestCase(TestCase):
|
||||
def setUp(self):
|
||||
self.factory = RequestFactory()
|
||||
|
||||
def test_ingest_view_no_alerts(self):
|
||||
@patch("ingest.views.send_new_issue_alert")
|
||||
@patch("ingest.views.send_regression_alert")
|
||||
def test_ingest_view_no_alerts(self, send_regression_alert, send_new_issue_alert):
|
||||
project = Project.objects.create(
|
||||
alert_on_new_issue=False,
|
||||
name="test",
|
||||
@@ -29,6 +32,25 @@ class IngestViewTestCase(TestCase):
|
||||
project,
|
||||
request,
|
||||
)
|
||||
self.assertFalse(send_regression_alert.delay.called)
|
||||
self.assertFalse(send_new_issue_alert.delay.called)
|
||||
|
||||
@patch("ingest.views.send_new_issue_alert")
|
||||
@patch("ingest.views.send_regression_alert")
|
||||
def test_ingest_view_new_issue_alert(self, send_regression_alert, send_new_issue_alert):
|
||||
project = Project.objects.create(
|
||||
alert_on_new_issue=True,
|
||||
name="test",
|
||||
)
|
||||
request = self.factory.post("/api/1/store/")
|
||||
|
||||
BaseIngestAPIView().process_event(
|
||||
create_event_data(),
|
||||
project,
|
||||
request,
|
||||
)
|
||||
self.assertTrue(send_new_issue_alert.delay.called)
|
||||
self.assertFalse(send_regression_alert.delay.called)
|
||||
|
||||
|
||||
class TimeZoneTesCase(TestCase):
|
||||
|
||||
@@ -21,6 +21,7 @@ from events.models import Event
|
||||
from releases.models import create_release_if_needed
|
||||
from bugsink.registry import get_pc_registry
|
||||
from bugsink.period_counter import PeriodCounter
|
||||
from alerts.tasks import send_new_issue_alert, send_regression_alert
|
||||
|
||||
from .negotiation import IgnoreClientContentNegotiation
|
||||
from .parsers import EnvelopeParser
|
||||
@@ -108,11 +109,11 @@ class BaseIngestAPIView(APIView):
|
||||
|
||||
if issue_created:
|
||||
if ingested_event.project.alert_on_new_issue:
|
||||
alert_for_new_issue.delay(issue)
|
||||
send_new_issue_alert.delay(issue)
|
||||
|
||||
elif issue_is_regression(issue, event.release): # new issues cannot be regressions by definition, hence 'else'
|
||||
if ingested_event.project.alert_on_regression:
|
||||
alert_for_regression.delay(issue)
|
||||
send_regression_alert.delay(issue)
|
||||
|
||||
IssueResolver.reopen(issue)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import uuid
|
||||
|
||||
from django.db import models
|
||||
|
||||
from alerts.tasks import send_unmute_notification
|
||||
from alerts.tasks import send_unmute_alert
|
||||
|
||||
|
||||
class Issue(models.Model):
|
||||
@@ -96,7 +96,7 @@ class Issue(models.Model):
|
||||
# (note: we can expect project to be set, because it will be None only when projects are deleted in
|
||||
# which case no more unmuting happens)
|
||||
if self.project.alert_on_unmute:
|
||||
send_unmute_notification.delay(self.id)
|
||||
send_unmute_alert.delay(self.id)
|
||||
|
||||
|
||||
class IssueResolver(object):
|
||||
|
||||
@@ -272,8 +272,8 @@ class UnmuteTestCase(TestCase):
|
||||
def tearDown(self):
|
||||
reset_pc_registry()
|
||||
|
||||
@patch("issues.models.send_unmute_notification")
|
||||
def test_unmute_simple_case(self, send_unmute_notification):
|
||||
@patch("issues.models.send_unmute_alert")
|
||||
def test_unmute_simple_case(self, send_unmute_alert):
|
||||
project = Project.objects.create()
|
||||
|
||||
issue = Issue.objects.create(
|
||||
@@ -292,10 +292,10 @@ class UnmuteTestCase(TestCase):
|
||||
self.assertEquals("[]", Issue.objects.get(id=issue.id).unmute_on_volume_based_conditions)
|
||||
self.assertEquals({}, registry.by_issue[issue.id].event_listeners[TL_DAY])
|
||||
|
||||
self.assertEquals(1, send_unmute_notification.delay.call_count)
|
||||
self.assertEquals(1, send_unmute_alert.delay.call_count)
|
||||
|
||||
@patch("issues.models.send_unmute_notification")
|
||||
def test_unmute_two_simultaneously_should_lead_to_one_notification(self, send_unmute_notification):
|
||||
@patch("issues.models.send_unmute_alert")
|
||||
def test_unmute_two_simultaneously_should_lead_to_one_alert(self, send_unmute_alert):
|
||||
project = Project.objects.create()
|
||||
|
||||
issue = Issue.objects.create(
|
||||
@@ -317,4 +317,4 @@ class UnmuteTestCase(TestCase):
|
||||
self.assertEquals("[]", Issue.objects.get(id=issue.id).unmute_on_volume_based_conditions)
|
||||
self.assertEquals({}, registry.by_issue[issue.id].event_listeners[TL_DAY])
|
||||
|
||||
self.assertEquals(1, send_unmute_notification.delay.call_count)
|
||||
self.assertEquals(1, send_unmute_alert.delay.call_count)
|
||||
|
||||
Reference in New Issue
Block a user