Skip to content

Commit

Permalink
refactor TestGetSerializedMessages in pytest style
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Nov 27, 2024
1 parent cd4dede commit c4ad74f
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions lacommunaute/notification/tests/tests_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.test import TestCase
from faker import Faker

from lacommunaute.forum_conversation.factories import TopicFactory
from lacommunaute.forum_conversation.factories import PostFactory, TopicFactory
from lacommunaute.notification.factories import EmailSentTrackFactory, NotificationFactory
from lacommunaute.notification.models import EmailSentTrack
from lacommunaute.notification.utils import (
Expand Down Expand Up @@ -50,24 +50,15 @@ def test_order_by_date_joined(self):
self.assertEqual(list(collect_new_users_for_onboarding()), list(User.objects.all().order_by("date_joined")))


class GetSeriaizedMessagesTestCase(TestCase):
@classmethod
def setUpTestData(cls):
cls.topic = TopicFactory(with_post=True)

def test_get_serialized_messages(self):
post = self.topic.first_post
class TestGetSerializedMessages:
def test_post_is_not_topic_head(self, db):
post = PostFactory(topic=TopicFactory(with_post=True))
notifications = [NotificationFactory(post=post)]

serialized_content = get_serialized_messages(notifications)
self.assertEqual(
serialized_content,
[
{
"poster": post.poster_display_name,
"action": f"a répondu à '{post.subject}'",
"forum": self.topic.forum.name,
"url": self.topic.get_absolute_url(with_fqdn=True),
}
],
)
assert get_serialized_messages(notifications) == [
{
"poster": post.poster_display_name,
"action": f"a répondu à '{post.subject}'",
"forum": post.topic.forum.name,
"url": post.topic.get_absolute_url(with_fqdn=True),
}
]

0 comments on commit c4ad74f

Please sign in to comment.