From c4ad74ff0deb5cb2c461ed2e59b1309a4fa081c9 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Wed, 27 Nov 2024 14:29:08 +0100 Subject: [PATCH] refactor TestGetSerializedMessages in pytest style --- .../notification/tests/tests_utils.py | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/lacommunaute/notification/tests/tests_utils.py b/lacommunaute/notification/tests/tests_utils.py index 7bcacfc1a..dd15bb6f2 100644 --- a/lacommunaute/notification/tests/tests_utils.py +++ b/lacommunaute/notification/tests/tests_utils.py @@ -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 ( @@ -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), + } + ]