Skip to content

Commit

Permalink
use assertContains in pytest-style tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Jul 26, 2023
1 parent 398c511 commit 8f8fe7a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lacommunaute/forum/tests/test_CategoryForumListView.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest # noqa
from django.urls import reverse
from pytest_django.asserts import assertContains

from lacommunaute.forum.enums import Kind as ForumKind
from lacommunaute.forum.factories import ForumFactory
Expand All @@ -9,9 +10,8 @@
def test_context(client, db):
url = reverse("forum_extension:documentation")
response = client.get(url)
assert response.status_code == 200
assert "forum/category_forum_list.html" == response.templates[0].name
assert reverse("pages:statistiques") in str(response.content)
assertContains(response, reverse("pages:statistiques"), status_code=200)


def test_queryset(client, db):
Expand Down
11 changes: 7 additions & 4 deletions lacommunaute/forum_upvote/tests/test_forumupvoteview.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest # noqa
from django.urls import reverse
from machina.core.db.models import get_model
from pytest_django.asserts import assertContains

from lacommunaute.forum.factories import ForumFactory
from lacommunaute.forum_upvote.models import UpVote
Expand Down Expand Up @@ -32,14 +33,16 @@ def test_upvote_downvote_with_permission(client, db):

# upvote
response = client.post(url, data=form_data)
assert response.status_code == 200
assert '<i class="ri-bookmark-fill" aria-hidden="true"></i><span class="ml-1">1</span>' in str(response.content)
assertContains(
response, '<i class="ri-bookmark-fill" aria-hidden="true"></i><span class="ml-1">1</span>', status_code=200
)
assert UpVote.objects.get()

# downvote
response = client.post(url, data=form_data)
assert response.status_code == 200
assert '<i class="ri-bookmark-line" aria-hidden="true"></i><span class="ml-1">0</span>' in str(response.content)
assertContains(
response, '<i class="ri-bookmark-line" aria-hidden="true"></i><span class="ml-1">0</span>', status_code=200
)
assert not UpVote.objects.all()


Expand Down
11 changes: 7 additions & 4 deletions lacommunaute/forum_upvote/tests/test_postupvoteview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.contrib.contenttypes.models import ContentType
from django.urls import reverse
from machina.core.db.models import get_model
from pytest_django.asserts import assertContains

from lacommunaute.forum.factories import ForumFactory
from lacommunaute.forum_conversation.factories import TopicFactory
Expand Down Expand Up @@ -34,8 +35,9 @@ def test_upvote_with_permission(client, db):

# upvote
response = client.post(url, data=form_data)
assert response.status_code == 200
assert '<i class="ri-bookmark-fill" aria-hidden="true"></i><span class="ml-1">1</span>' in str(response.content)
assertContains(
response, '<i class="ri-bookmark-fill" aria-hidden="true"></i><span class="ml-1">1</span>', status_code=200
)
assert UpVote.objects.get(
voter_id=user.id,
object_id=topic.first_post.id,
Expand All @@ -44,8 +46,9 @@ def test_upvote_with_permission(client, db):

# downvote
response = client.post(url, data=form_data)
assert response.status_code == 200
assert '<i class="ri-bookmark-line" aria-hidden="true"></i><span class="ml-1">0</span>' in str(response.content)
assertContains(
response, '<i class="ri-bookmark-line" aria-hidden="true"></i><span class="ml-1">0</span>', status_code=200
)
assert not UpVote.objects.all()


Expand Down

0 comments on commit 8f8fe7a

Please sign in to comment.