Skip to content

Commit

Permalink
fix(notification): tests
Browse files Browse the repository at this point in the history
  • Loading branch information
calummackervoy committed Aug 5, 2024
1 parent e2f3400 commit 1bb3873
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 5 additions & 1 deletion lacommunaute/notification/factories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import random
from datetime import timedelta

import factory
import factory.django
from django.utils import timezone
from faker import Faker

from lacommunaute.notification.enums import EmailSentTrackKind
Expand Down Expand Up @@ -28,4 +32,4 @@ class Meta:
model = Notification

class Params:
is_sent = factory.Trait(sent_at=faker.past_datetime())
is_sent = factory.Trait(sent_at=(timezone.now() - timedelta(days=random.randint(0, 90))))
8 changes: 4 additions & 4 deletions lacommunaute/notification/tests/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ def test_mark_topic_posts_read(self):
Notification.objects.mark_topic_posts_read(topic, user)

self.assertEqual(
Notification.objects.filter(
sent_at__isnull=False, post=topic.first_post, recipient=user.email, sent_at=F("created")
).count(),
Notification.objects.filter(post=topic.first_post, recipient=user.email, sent_at=F("created")).count(),
2,
)

Expand All @@ -56,12 +54,14 @@ def test_mark_topic_posts_read_doesnt_impact_old_notifications(self):
topic = TopicFactory(with_post=True)

old_notification = NotificationFactory(recipient=user.email, post=topic.first_post, is_sent=True)
self.assertIsNotNone(old_notification.sent_at)
self.assertNotEqual(str(old_notification.sent_at), str(old_notification.created))
original_send_time = old_notification.sent_at

Notification.objects.mark_topic_posts_read(topic, user)

old_notification.refresh_from_db()
self.assertNotEqual(str(old_notification.sent_at), str(old_notification.created))
self.assertEqual(original_send_time, old_notification.sent_at)

def test_mark_topic_posts_read_doesnt_impact_other_notifications(self):
user = UserFactory()
Expand Down

0 comments on commit 1bb3873

Please sign in to comment.