Skip to content

Commit

Permalink
Remove those ugly mock.patch
Browse files Browse the repository at this point in the history
  • Loading branch information
francoisfreitag authored and vincentporte committed Feb 13, 2024
1 parent a820486 commit a919bab
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions lacommunaute/forum_conversation/tests/tests_views_htmx.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from unittest.mock import patch

from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.test import RequestFactory, TestCase
from django.urls import reverse
from faker import Faker
Expand Down Expand Up @@ -332,11 +331,9 @@ def test_form_is_invalid(self):

self.assertEqual(response.status_code, 500)

@patch(
"lacommunaute.forum_conversation.views_htmx.PostFeedCreateView.perform_permissions_check", return_value=True
)
@patch("machina.apps.forum_permission.handler.PermissionHandler.can_post_without_approval", return_value=True)
def test_create_post_as_authenticated_user(self, *args):
assign_perm("can_reply_to_topics", self.user, self.topic.forum)
assign_perm("can_post_without_approval", self.user, self.topic.forum)
self.client.force_login(self.user)

response = self.client.post(self.url, data={"content": self.content})
Expand All @@ -352,11 +349,10 @@ def test_create_post_as_authenticated_user(self, *args):
{"content": self.content, "username": None, "approved": True, "update_reason": None},
)

@patch(
"lacommunaute.forum_conversation.views_htmx.PostFeedCreateView.perform_permissions_check", return_value=True
)
@patch("machina.apps.forum_permission.handler.PermissionHandler.can_post_without_approval", return_value=True)
def test_create_post_as_bounced_not_bounced_anonymous(self, *args):
user = AnonymousUser()
assign_perm("can_reply_to_topics", user, self.topic.forum)
assign_perm("can_post_without_approval", user, self.topic.forum)
username = faker.email()

response = self.client.post(self.url, {"content": self.content, "username": username})
Expand All @@ -381,10 +377,9 @@ def test_create_post_as_bounced_not_bounced_anonymous(self, *args):
{"content": self.content, "username": username, "approved": False},
)

@patch(
"lacommunaute.forum_conversation.views_htmx.PostFeedCreateView.perform_permissions_check", return_value=True
)
def test_create_post_with_nonfr_content(self, *args):
def test_create_post_with_nonfr_content(self):
user = AnonymousUser()
assign_perm("can_reply_to_topics", user, self.topic.forum)
response = self.client.post(
self.url, {"content": "популярные лучшие песни слушать онлайн", "username": faker.email()}
)
Expand All @@ -400,10 +395,9 @@ def test_create_post_with_nonfr_content(self, *args):
},
)

@patch(
"lacommunaute.forum_conversation.views_htmx.PostFeedCreateView.perform_permissions_check", return_value=True
)
def test_create_post_with_html_content(self, *args):
def test_create_post_with_html_content(self):
user = AnonymousUser()
assign_perm("can_reply_to_topics", user, self.topic.forum)
response = self.client.post(
self.url,
{
Expand All @@ -423,12 +417,12 @@ def test_create_post_with_html_content(self, *args):
},
)

@patch(
"lacommunaute.forum_conversation.views_htmx.PostFeedCreateView.perform_permissions_check", return_value=True
)
def test_create_post_with_bounced_domain_name(self, *args):
def test_create_post_with_bounced_domain_name(self):
BouncedDomainNameFactory(domain="blocked.com")

user = AnonymousUser()
assign_perm("can_reply_to_topics", user, self.topic.forum)

response = self.client.post(self.url, {"content": "la communauté", "username": "[email protected]"})

self.assertEqual(response.status_code, 200)
Expand Down

0 comments on commit a919bab

Please sign in to comment.