Skip to content

Commit

Permalink
feat(forum): add upvotes_count methode on Forum model
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Jul 24, 2023
1 parent bddefec commit 73d07e6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lacommunaute/forum/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ def get_unanswered_topics(self):
@cached_property
def count_unanswered_topics(self):
return self.get_unanswered_topics().count()

def upvotes_count(self):
return self.upvotes.count()
7 changes: 7 additions & 0 deletions lacommunaute/forum/tests/tests_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from lacommunaute.forum.factories import ForumFactory
from lacommunaute.forum.models import Forum
from lacommunaute.forum_conversation.factories import TopicFactory
from lacommunaute.users.factories import UserFactory


class ForumManagerTest(TestCase):
Expand Down Expand Up @@ -50,3 +51,9 @@ def test_get_absolute_url(self):
forum.get_absolute_url(),
f"/forum/{forum.slug}-{forum.pk}/",
)

def test_upvotes_count(self):
forum = ForumFactory()
self.assertEqual(forum.upvotes_count(), 0)
forum.upvotes.create(voter=UserFactory())
self.assertEqual(forum.upvotes_count(), 1)

0 comments on commit 73d07e6

Please sign in to comment.