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. Use faker.sentence() instead of faker.text
  • Loading branch information
vincentporte committed Feb 8, 2024
1 parent 9ef4511 commit b71d001
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 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": faker.sentence()}

def test_subject_is_hidden(self):
form = PostForm()
Expand Down
9 changes: 5 additions & 4 deletions lacommunaute/forum_conversation/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": faker.sentence()}

def test_get_success_url(self):
view = TopicCreateView()
Expand Down Expand Up @@ -108,6 +108,7 @@ def test_topic_create_as_anonymous_user(self, *args):
self.assertEqual(response.status_code, 200)
self.assertEqual(1, Topic.objects.count())
topic = Topic.objects.first()
self.assertIsNone(topic.first_post.update_reason)
self.assertEqual(self.post_data["subject"], topic.subject)
self.assertEqual(self.post_data["subject"], topic.first_post.subject)
self.assertEqual(self.post_data["content"], topic.first_post.content.raw)
Expand Down Expand Up @@ -208,7 +209,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": faker.sentence(),
"tags": [Tag.objects.first().pk, Tag.objects.last().pk],
}

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

self.client.force_login(self.poster)

post_data = {"subject": "s", "content": faker.text(max_nb_chars=20)}
post_data = {"subject": "s", "content": faker.sentence()}
response = self.client.post(
self.url,
post_data,
Expand Down Expand Up @@ -372,7 +373,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": faker.sentence()}

def test_delete_post_button_is_visible(self, *args):
self.client.force_login(self.poster)
Expand Down
2 changes: 1 addition & 1 deletion lacommunaute/forum_conversation/tests/tests_views_htmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def setUpTestData(cls):
"slug": cls.topic.slug,
},
)
cls.content = faker.text(max_nb_chars=20)
cls.content = faker.sentence()

def test_get_method_unallowed(self):
self.client.force_login(self.user)
Expand Down

0 comments on commit b71d001

Please sign in to comment.