Skip to content

Commit

Permalink
refactor can_certify_topic shortcut test
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Feb 26, 2025
1 parent bfc3380 commit a28f761
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions lacommunaute/forum_conversation/tests/tests_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.contrib.auth.models import AnonymousUser
from django.test import TestCase

from lacommunaute.forum.factories import ForumFactory
from lacommunaute.forum_conversation.factories import PostFactory, TopicFactory
from lacommunaute.forum_conversation.shortcuts import (
can_certify_post,
Expand Down Expand Up @@ -75,21 +74,13 @@ def test_topic_has_been_upvoted_by_the_user(self):
self.assertTrue(post.has_upvoted)


class CanCertifyPostShortcutTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.user = UserFactory.create()
cls.forum = ForumFactory.create()

def test_user_is_not_authenticated(self):
self.assertFalse(can_certify_post(AnonymousUser()))

def test_user_is_staff(self):
self.user.is_staff = True
self.assertTrue(can_certify_post(self.user))
@pytest.mark.parametrize(
"user,has_right",
[(lambda: AnonymousUser(), False), (lambda: UserFactory(), False), (lambda: UserFactory(is_staff=True), True)],
)
def test_can_certify_post(db, user, has_right):
assert can_certify_post(user()) == has_right

def test_user_is_not_staff(self):
self.assertFalse(can_certify_post(self.user))

@pytest.mark.parametrize(
"user,has_right",
Expand Down

0 comments on commit a28f761

Please sign in to comment.