Skip to content

Commit

Permalink
fix(forum_conversation): Résolution des erreurs de tests sur les cont…
Browse files Browse the repository at this point in the history
…enus des messages (#754)

## Description

🎸 `faker.sentences(2)` produit des contenus considérés comme -Non-FR-
par la lib `langdetect` malgré le paramétrage
`Faker(settings.LANGUAGE_CODE)`.
🎸 Remplacement de la génération de 2 phrases, par un paragraphe de 5
phrases : `faker.paragraph(nb_sentences=5)` dans les tests des
formulaires de l'app `forum_conversation`

## Type de changement

🪲 Correction de bug (changement non cassant qui corrige un problème).
🚧 technique
  • Loading branch information
vincentporte authored Aug 14, 2024
1 parent 3c2a5a0 commit 8e0f35d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions lacommunaute/forum_conversation/tests/tests_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_create_topic_as_anonymous(self, db, client, public_forum):

response = client.post(
get_create_topic_url(public_forum),
data={"subject": "Test", "content": faker.sentences(2), "username": username},
data={"subject": "Test", "content": faker.paragraph(nb_sentences=5), "username": username},
)
assert response.status_code == 302

Expand All @@ -120,7 +120,7 @@ def test_update_anonymous_topic_as_self(self, db, client, public_forum):
session = client.session
session["anonymous_topic"] = topic.first_post.anonymous_key

data = {"subject": faker.word(), "content": faker.sentences(2), "username": username}
data = {"subject": faker.word(), "content": faker.paragraph(nb_sentences=5), "username": username}
response = client.post(get_update_topic_url(topic), data=data)
assert response.status_code == 302

Expand All @@ -139,7 +139,7 @@ def test_update_anonymous_topic_as_superuser(self, db, client, public_forum):

data = {
"subject": faker.word(),
"content": faker.sentences(2),
"content": faker.paragraph(nb_sentences=5),
**superuser_hidden_fields,
}
response = client.post(get_update_topic_url(topic), data=data)
Expand All @@ -157,7 +157,7 @@ def test_create_topic_as_authenticated(self, db, client, public_forum):
client.force_login(user)

response = client.post(
get_create_topic_url(public_forum), data={"subject": "Test", "content": faker.sentences(2)}
get_create_topic_url(public_forum), data={"subject": "Test", "content": faker.paragraph(nb_sentences=5)}
)
assert response.status_code == 302

Expand All @@ -173,7 +173,7 @@ def test_update_authenticated_topic_as_self(self, db, client, public_forum):
user = topic.poster
client.force_login(user)

data = {"subject": faker.word(), "content": faker.sentences(2)}
data = {"subject": faker.word(), "content": faker.paragraph(nb_sentences=5)}
response = client.post(get_update_topic_url(topic), data=data)
assert response.status_code == 302

Expand All @@ -192,7 +192,7 @@ def test_update_authenticated_topic_as_superuser(self, db, client, public_forum)

data = {
"subject": faker.word(),
"content": faker.sentences(2),
"content": faker.paragraph(nb_sentences=5),
**superuser_hidden_fields,
}
response = client.post(get_update_topic_url(topic), data=data)
Expand Down Expand Up @@ -231,7 +231,9 @@ def test_reply_as_anonymous(self, db, client, public_forum):
topic = TopicFactory(forum=public_forum, with_post=True)
username = faker.email()

response = client.post(get_reply_topic_url(topic), data={"content": faker.sentences(2), "username": username})
response = client.post(
get_reply_topic_url(topic), data={"content": faker.paragraph(nb_sentences=5), "username": username}
)
assert response.status_code == 200 # htmx view

topic.refresh_from_db()
Expand All @@ -247,7 +249,7 @@ def test_update_anonymous_reply_as_self(self, db, client, public_forum):
session = client.session
session["anonymous_post"] = post.anonymous_key

data = {"content": faker.sentences(2), "username": username}
data = {"content": faker.paragraph(nb_sentences=5), "username": username}
response = client.post(get_post_update_url(post), data=data)
assert response.status_code == 302

Expand All @@ -263,7 +265,7 @@ def test_update_anonymous_reply_as_superuser(self, db, client, public_forum):
superuser = UserFactory(is_superuser=True)
client.force_login(superuser)

data = {"content": faker.sentences(2), **superuser_hidden_fields}
data = {"content": faker.paragraph(nb_sentences=5), **superuser_hidden_fields}
response = client.post(get_post_update_url(post), data=data)
assert response.status_code == 302

Expand All @@ -278,7 +280,7 @@ def test_reply_as_authenticated(self, db, client, public_forum):
user = UserFactory()
client.force_login(user)

response = client.post(get_reply_topic_url(topic), data={"content": faker.sentences(2)})
response = client.post(get_reply_topic_url(topic), data={"content": faker.paragraph(nb_sentences=5)})
assert response.status_code == 200

topic.refresh_from_db()
Expand All @@ -295,7 +297,7 @@ def test_update_authenticated_reply_as_self(self, db, client, public_forum):
user = post.poster
client.force_login(user)

data = {"content": faker.sentences(2)}
data = {"content": faker.paragraph(nb_sentences=5)}
response = client.post(get_post_update_url(post), data=data)
assert response.status_code == 302

Expand All @@ -311,7 +313,7 @@ def test_update_authenticated_reply_as_superuser(self, db, client, public_forum)
superuser = UserFactory(is_superuser=True)
client.force_login(superuser)

data = {"content": faker.sentences(2), **superuser_hidden_fields}
data = {"content": faker.paragraph(nb_sentences=5), **superuser_hidden_fields}
response = client.post(get_post_update_url(post), data=data)
assert response.status_code == 302

Expand Down

0 comments on commit 8e0f35d

Please sign in to comment.