Skip to content

Commit

Permalink
Add email message check to test, remove typing that was causing problems
Browse files Browse the repository at this point in the history
  • Loading branch information
mderynck committed Jul 31, 2024
1 parent 3e16f5f commit 45e0800
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
13 changes: 1 addition & 12 deletions engine/apps/email/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import typing
import uuid

from django.db import models

if typing.TYPE_CHECKING:
from apps.alerts.models import Alert, AlertGroup
from apps.base.models import UserNotificationPolicy
from apps.user_management.models import User


class EmailMessageQuerySet(models.QuerySet):
def create(self, **kwargs):
Expand All @@ -20,12 +14,7 @@ def create(self, **kwargs):


class EmailMessage(models.Model):
represents_alert: "Alert"
represents_alert_group: "AlertGroup"
notification_policy: typing.Optional["UserNotificationPolicy"]
receiver: typing.Optional["User"]

objects: models.Manager["EmailMessage"] = EmailMessageQuerySet.as_manager()
objects = EmailMessageQuerySet.as_manager()

message_uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)

Expand Down
5 changes: 4 additions & 1 deletion engine/apps/email/tests/test_notify_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from apps.base.models import UserNotificationPolicy, UserNotificationPolicyLogRecord
from apps.email.alert_rendering import build_subject_and_message
from apps.email.models import EmailMessage
from apps.email.tasks import get_from_email, notify_user_async
from apps.user_management.subscription_strategy.free_public_beta_subscription_strategy import (
FreePublicBetaSubscriptionStrategy,
Expand Down Expand Up @@ -239,5 +240,7 @@ def test_notify_user_fallback_default_policy(
notify_user_async(user.pk, alert_group.pk, None)
assert len(mail.outbox) == 1

log_record = UserNotificationPolicyLogRecord.objects.filter(author=user, alert_group=alert_group).last()
log_record = UserNotificationPolicyLogRecord.objects.filter(author=user, alert_group=alert_group).first()
assert log_record.type == UserNotificationPolicyLogRecord.TYPE_PERSONAL_NOTIFICATION_SUCCESS

EmailMessage.objects.get(receiver=user, represents_alert_group=alert_group, notification_policy=None)

0 comments on commit 45e0800

Please sign in to comment.