Skip to content

Commit

Permalink
fix flakyness of posting content tests\nlangdetect needs enough words…
Browse files Browse the repository at this point in the history
… to predict content language. Init fr faker session and use ' '.join(faker.sentences(4)) instead of faker.text
  • Loading branch information
vincentporte committed Feb 8, 2024
1 parent 3206a13 commit d47ef54
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions lacommunaute/forum_conversation/tests/tests_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from lacommunaute.forum_conversation.forms import PostForm


faker = Faker()
faker = Faker("fr_FR")


class PostFormTest(TestCase):
Expand All @@ -17,7 +17,7 @@ def setUpTestData(cls):
cls.topic = TopicFactory(with_post=True)
cls.user = cls.topic.poster
cls.forum = cls.topic.forum
cls.form_data = {"subject": faker.text(max_nb_chars=10), "content": faker.text(max_nb_chars=30)}
cls.form_data = {"subject": faker.text(max_nb_chars=10), "content": " ".join(faker.sentences(4))}

def test_subject_is_hidden(self):
form = PostForm()
Expand Down
10 changes: 5 additions & 5 deletions lacommunaute/forum_conversation/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
from lacommunaute.users.factories import UserFactory


faker = Faker()
faker = Faker("fr_FR")

PermissionHandler = get_class("forum_permission.handler", "PermissionHandler")
TopicReadTrack = get_model("forum_tracking", "TopicReadTrack")
Expand All @@ -50,7 +50,7 @@ def setUpTestData(cls):
},
)

cls.post_data = {"subject": faker.text(max_nb_chars=10), "content": faker.text(max_nb_chars=30)}
cls.post_data = {"subject": faker.text(max_nb_chars=10), "content": " ".join(faker.sentences(4))}

def test_get_success_url(self):
view = TopicCreateView()
Expand Down Expand Up @@ -208,7 +208,7 @@ def test_checked_tags_are_saved(self, *args):
self.client.force_login(self.poster)
post_data = {
"subject": faker.text(max_nb_chars=5),
"content": faker.text(max_nb_chars=5),
"content": " ".join(faker.sentences(4)),
"tags": [Tag.objects.first().pk, Tag.objects.last().pk],
}

Expand Down Expand Up @@ -266,7 +266,7 @@ def test_topic_is_marked_as_read_when_updated(self):

self.client.force_login(self.poster)

post_data = {"subject": "s", "content": "c"}
post_data = {"subject": "s", "content": " ".join(faker.sentences(4))}
response = self.client.post(
self.url,
post_data,
Expand Down Expand Up @@ -372,7 +372,7 @@ def setUpTestData(cls):
"pk": cls.post.pk,
}
cls.url = reverse("forum_conversation:post_update", kwargs=cls.kwargs)
cls.post_data = {"content": faker.text(max_nb_chars=20)}
cls.post_data = {"content": " ".join(faker.sentences(4))}

def test_delete_post_button_is_visible(self, *args):
self.client.force_login(self.poster)
Expand Down
12 changes: 6 additions & 6 deletions lacommunaute/forum_conversation/tests/tests_views_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
ForumReadTrack = get_model("forum_tracking", "ForumReadTrack")
assign_perm = get_class("forum_permission.shortcuts", "assign_perm")
PermissionHandler = get_class("forum_permission.handler", "PermissionHandler")
faker = Faker()
faker = Faker("fr_FR")


class ForumTopicListViewTest(TestCase):
Expand Down Expand Up @@ -291,7 +291,7 @@ def setUpTestData(cls):
"slug": cls.topic.slug,
},
)
cls.content = faker.text(max_nb_chars=20)
cls.content = " ".join(faker.sentences(4))

def test_get_method_unallowed(self):
self.client.force_login(self.user)
Expand Down Expand Up @@ -346,8 +346,8 @@ def test_create_post_as_authenticated_user(self, *args):
self.topic.refresh_from_db()
self.assertEqual(self.topic.posts.count(), 2)
self.assertEqual(
self.topic.posts.values("content", "username", "approved").last(),
{"content": self.content, "username": None, "approved": True},
self.topic.posts.values("content", "username", "approved", "update_reason").last(),
{"content": self.content, "username": None, "approved": True, "update_reason": None},
)

@patch(
Expand All @@ -363,8 +363,8 @@ def test_create_post_as_bounced_not_bounced_anonymous(self, *args):
self.topic.refresh_from_db()
self.assertEqual(self.topic.posts.count(), 2)
self.assertEqual(
self.topic.posts.values("content", "username", "approved").last(),
{"content": self.content, "username": username, "approved": True},
self.topic.posts.values("content", "username", "approved", "update_reason").last(),
{"content": self.content, "username": username, "approved": True, "update_reason": None},
)

BouncedEmailFactory(email=username).save()
Expand Down

0 comments on commit d47ef54

Please sign in to comment.