diff --git a/lacommunaute/forum/tests/tests_model.py b/lacommunaute/forum/tests/tests_model.py index dcd0a13a..18130031 100644 --- a/lacommunaute/forum/tests/tests_model.py +++ b/lacommunaute/forum/tests/tests_model.py @@ -9,9 +9,9 @@ class ForumModelTest(TestCase): def test_get_unanswered_topics(self): - topic1 = TopicFactory(forum=ForumFactory(), posts_count=1) - topic2 = TopicFactory(forum=ForumFactory(parent=topic1.forum), posts_count=1) - TopicFactory(forum=ForumFactory(), posts_count=1) + topic1 = TopicFactory(forum=ForumFactory(), with_post=True) + topic2 = TopicFactory(forum=ForumFactory(parent=topic1.forum), with_post=True) + TopicFactory(forum=ForumFactory(), with_post=True) unanswered_topics = topic1.forum.get_unanswered_topics() self.assertEqual(unanswered_topics.count(), 2) @@ -19,8 +19,8 @@ def test_get_unanswered_topics(self): self.assertIn(topic2, unanswered_topics) def test_count_unanswered_topics(self): - topic = TopicFactory(forum=ForumFactory(), posts_count=1) - TopicFactory(forum=ForumFactory(parent=topic.forum), posts_count=1) + topic = TopicFactory(forum=ForumFactory(), with_post=True) + TopicFactory(forum=ForumFactory(parent=topic.forum), with_post=True) self.assertEqual(topic.forum.count_unanswered_topics, 2) def test_get_absolute_url(self): diff --git a/lacommunaute/forum_conversation/factories.py b/lacommunaute/forum_conversation/factories.py index cdd4c0eb..2caaff62 100644 --- a/lacommunaute/forum_conversation/factories.py +++ b/lacommunaute/forum_conversation/factories.py @@ -58,6 +58,11 @@ class Params: poster=factory.SelfAttribute("topic.poster"), ) ) + with_disapproved_post = factory.Trait( + post=factory.RelatedFactory( + PostFactory, factory_related_name="topic", poster=factory.SelfAttribute("topic.poster"), approved=False + ) + ) @factory.post_generation def with_poll_vote(self, create, extracted, **kwargs): diff --git a/lacommunaute/forum_conversation/tests/tests_models.py b/lacommunaute/forum_conversation/tests/tests_models.py index f74169e7..25fab242 100644 --- a/lacommunaute/forum_conversation/tests/tests_models.py +++ b/lacommunaute/forum_conversation/tests/tests_models.py @@ -41,13 +41,13 @@ class TopicManagerTest(TestCase): def test_unanswered(self): forum = ForumFactory() - TopicFactory(forum=forum, posts_count=0) - topic = TopicFactory(forum=forum, posts_count=1) - TopicFactory(forum=forum, posts_count=2) + TopicFactory(forum=forum) + topic = TopicFactory(forum=forum, with_post=True) + TopicFactory(forum=forum, with_post=True, answered=True) - TopicFactory(forum=forum, posts_count=1, status=Topic.TOPIC_LOCKED) - TopicFactory(forum=forum, posts_count=1, type=Topic.TOPIC_ANNOUNCE) - TopicFactory(forum=forum, posts_count=1, approved=False) + TopicFactory(forum=forum, with_post=True, status=Topic.TOPIC_LOCKED) + TopicFactory(forum=forum, with_post=True, type=Topic.TOPIC_ANNOUNCE) + TopicFactory(forum=forum, with_disapproved_post=True) self.assertEqual(Topic.objects.unanswered().get(), topic) @@ -65,10 +65,10 @@ def test_optimized_for_topics_list_disapproved(self): self.assertEqual(Topic.objects.optimized_for_topics_list(1).count(), 0) def test_optimized_for_topics_list_type(self): - annonce = TopicFactory(type=Topic.TOPIC_ANNOUNCE) - sticky = TopicFactory(type=Topic.TOPIC_STICKY) - topic = TopicFactory(type=Topic.TOPIC_POST) - unapproved_topic = TopicFactory(type=Topic.TOPIC_POST, approved=False) + annonce = TopicFactory(type=Topic.TOPIC_ANNOUNCE, with_post=True) + sticky = TopicFactory(type=Topic.TOPIC_STICKY, with_post=True) + topic = TopicFactory(type=Topic.TOPIC_POST, with_post=True) + unapproved_topic = TopicFactory(type=Topic.TOPIC_POST, with_disapproved_post=True) qs = Topic.objects.optimized_for_topics_list(1)