|
@@ -8,6 +8,7 @@ from unittest import mock
|
|
|
import pytz
|
|
|
from django.contrib.auth.models import AnonymousUser
|
|
|
from django.core import mail
|
|
|
+from django.core.mail.message import EmailMultiAlternatives
|
|
|
from django.db.models import F
|
|
|
from django.utils import timezone
|
|
|
|
|
@@ -183,7 +184,9 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
self.adapter.notify(notification, ActionTargetType.ISSUE_OWNERS)
|
|
|
|
|
|
msg = mail.outbox[0]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
assert msg.subject == "[Sentry] BAR-1 - Hello world"
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert "my rule" in msg.alternatives[0][0]
|
|
|
|
|
|
def test_simple_snooze(self):
|
|
@@ -260,13 +263,13 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
|
|
|
def test_simple_notification_generic(self):
|
|
|
"""Test that an issue that is neither error nor performance type renders a generic email template"""
|
|
|
- event = self.store_event(
|
|
|
+ orig_event = self.store_event(
|
|
|
data={"message": "Hello world", "level": "error"}, project_id=self.project.id
|
|
|
)
|
|
|
- event = event.for_group(event.groups[0])
|
|
|
+ event = orig_event.for_group(orig_event.groups[0])
|
|
|
occurrence = IssueOccurrence(
|
|
|
- self.project.id,
|
|
|
uuid.uuid4().hex,
|
|
|
+ self.project.id,
|
|
|
uuid.uuid4().hex,
|
|
|
["some-fingerprint"],
|
|
|
"something bad happened",
|
|
@@ -297,6 +300,7 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
self.adapter.notify(notification, ActionTargetType.ISSUE_OWNERS)
|
|
|
|
|
|
msg = mail.outbox[0]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
assert msg.subject == f"[Sentry] BAR-1 - {occurrence.issue_title}"
|
|
|
checked_values = [
|
|
|
"Issue Data",
|
|
@@ -308,16 +312,17 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
"Value 3",
|
|
|
]
|
|
|
for checked_value in checked_values:
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert (
|
|
|
checked_value in msg.alternatives[0][0]
|
|
|
), f"{checked_value} not present in message"
|
|
|
|
|
|
def test_simple_notification_generic_no_evidence(self):
|
|
|
"""Test that an issue with no evidence that is neither error nor performance type renders a generic email template"""
|
|
|
- event = self.store_event(
|
|
|
+ orig_event = self.store_event(
|
|
|
data={"message": "Hello world", "level": "error"}, project_id=self.project.id
|
|
|
)
|
|
|
- event = event.for_group(event.groups[0])
|
|
|
+ event = orig_event.for_group(orig_event.groups[0])
|
|
|
occurrence = IssueOccurrence(
|
|
|
uuid.uuid4().hex,
|
|
|
self.project.id,
|
|
@@ -347,7 +352,9 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
self.adapter.notify(notification, ActionTargetType.ISSUE_OWNERS)
|
|
|
|
|
|
msg = mail.outbox[0]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
assert msg.subject == "[Sentry] BAR-1 - something bad happened"
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert "Issue Data" not in msg.alternatives[0][0]
|
|
|
|
|
|
def test_simple_notification_perf(self):
|
|
@@ -361,6 +368,7 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
self.adapter.notify(notification, ActionTargetType.ISSUE_OWNERS)
|
|
|
|
|
|
msg = mail.outbox[0]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
assert msg.subject == "[Sentry] BAR-1 - N+1 Query"
|
|
|
checked_values = [
|
|
|
"Transaction Name",
|
|
@@ -372,6 +380,7 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
"db - SELECT `books_author`.`id`, `books_author`.`name` FROM `books_autho...",
|
|
|
]
|
|
|
for checked_value in checked_values:
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert (
|
|
|
checked_value in msg.alternatives[0][0]
|
|
|
), f"{checked_value} not present in message"
|
|
@@ -542,8 +551,8 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
from django.template.defaultfilters import date
|
|
|
|
|
|
timestamp = datetime.now(tz=pytz.utc)
|
|
|
- local_timestamp = timezone.localtime(timestamp, pytz.timezone("Europe/Vienna"))
|
|
|
- local_timestamp = date(local_timestamp, "N j, Y, g:i:s a e")
|
|
|
+ local_timestamp_s = timezone.localtime(timestamp, pytz.timezone("Europe/Vienna"))
|
|
|
+ local_timestamp = date(local_timestamp_s, "N j, Y, g:i:s a e")
|
|
|
|
|
|
UserOption.objects.create(user=self.user, key="timezone", value="Europe/Vienna")
|
|
|
|
|
@@ -560,6 +569,7 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
|
|
|
assert len(mail.outbox) == 1
|
|
|
msg = mail.outbox[0]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
assert local_timestamp in str(msg.alternatives)
|
|
|
|
|
|
def test_notify_with_suspect_commits(self):
|
|
@@ -610,6 +620,7 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
},
|
|
|
project_id=self.project.id,
|
|
|
)
|
|
|
+ assert event.group is not None
|
|
|
GroupRelease.objects.create(
|
|
|
group_id=event.group.id, project_id=self.project.id, release_id=self.release.id
|
|
|
)
|
|
@@ -638,6 +649,8 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
assert len(mail.outbox) >= 1
|
|
|
|
|
|
msg = mail.outbox[-1]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert (
|
|
|
f"/settings/{organization.slug}/integrations/slack/?referrer=alert_email"
|
|
|
in msg.alternatives[0][0]
|
|
@@ -659,6 +672,8 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
assert len(mail.outbox) >= 1
|
|
|
|
|
|
msg = mail.outbox[-1]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert (
|
|
|
f"/settings/{organization.slug}/integrations/slack/?referrer=alert_email"
|
|
|
not in msg.alternatives[0][0]
|
|
@@ -679,6 +694,8 @@ class MailAdapterNotifyTest(BaseMailAdapterTest):
|
|
|
assert len(mail.outbox) >= 1
|
|
|
|
|
|
msg = mail.outbox[-1]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert (
|
|
|
f"/settings/{organization.slug}/integrations/slack/?referrer=alert_email"
|
|
|
not in msg.alternatives[0][0]
|
|
@@ -1107,6 +1124,7 @@ class MailAdapterNotifyIssueOwnersTest(BaseMailAdapterTest):
|
|
|
data={"message": "Hello world", "level": "error"}, project_id=self.project.id
|
|
|
)
|
|
|
# Header is based on the group substatus
|
|
|
+ assert event.group is not None
|
|
|
event.group.substatus = GroupSubStatus.REGRESSED
|
|
|
event.group.save()
|
|
|
|
|
@@ -1119,7 +1137,9 @@ class MailAdapterNotifyIssueOwnersTest(BaseMailAdapterTest):
|
|
|
self.adapter.notify(notification, ActionTargetType.ISSUE_OWNERS)
|
|
|
|
|
|
msg = mail.outbox[0]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
assert msg.subject == "[Sentry] BAR-1 - Hello world"
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert "Regressed issue" in msg.alternatives[0][0]
|
|
|
|
|
|
|
|
@@ -1536,8 +1556,10 @@ class MailAdapterHandleSignalTest(BaseMailAdapterTest):
|
|
|
|
|
|
assert len(mail.outbox) == 1
|
|
|
msg = mail.outbox[0]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
|
|
|
# email includes issue metadata
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert "group-header" in msg.alternatives[0][0]
|
|
|
assert "enhanced privacy" not in msg.body
|
|
|
|
|
@@ -1548,7 +1570,7 @@ class MailAdapterHandleSignalTest(BaseMailAdapterTest):
|
|
|
assert msg.to == [self.user.email]
|
|
|
|
|
|
def test_user_feedback__enhanced_privacy(self):
|
|
|
- self.organization.update(flags=F("flags").bitor(Organization.flags.enhanced_privacy))
|
|
|
+ self.organization.update(flags=F("flags").bitor(Organization.flags.enhanced_privacy)) # type: ignore[attr-defined]
|
|
|
assert self.organization.flags.enhanced_privacy.is_set is True
|
|
|
NotificationSetting.objects.update_settings(
|
|
|
ExternalProviders.EMAIL,
|
|
@@ -1567,8 +1589,10 @@ class MailAdapterHandleSignalTest(BaseMailAdapterTest):
|
|
|
|
|
|
assert len(mail.outbox) == 1
|
|
|
msg = mail.outbox[0]
|
|
|
+ assert isinstance(msg, EmailMultiAlternatives)
|
|
|
|
|
|
# email does not include issue metadata
|
|
|
+ assert isinstance(msg.alternatives[0][0], str)
|
|
|
assert "group-header" not in msg.alternatives[0][0]
|
|
|
assert "enhanced privacy" in msg.body
|
|
|
|