Skip to content

Commit

Permalink
wip tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Jul 3, 2023
1 parent 77aaa1c commit cc343c8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 48 deletions.
16 changes: 9 additions & 7 deletions lacommunaute/forum/tests/tests_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@


class ForumManagerTest(TestCase):
def test_private_forum(self):
def test_public_method(self):
forum = ForumFactory(kind=ForumKind.PUBLIC_FORUM)
ForumFactory(kind=ForumKind.NEWS)
ForumFactory(kind=ForumKind.PRIVATE_FORUM)
self.assertEqual(Forum.objects.public().count(), 0)

def test_public_forum(self):
forum = ForumFactory(kind=ForumKind.PUBLIC_FORUM)
self.assertEqual(Forum.objects.public().count(), 1)
self.assertIn(forum, Forum.objects.public())
self.assertEqual(forum, Forum.objects.public().get())


class ForumModelTest(TestCase):
Expand All @@ -53,3 +49,9 @@ def test_count_unanswered_topics(self):
topic = TopicFactory(forum=ForumFactory(), posts_count=1)
TopicFactory(forum=ForumFactory(parent=topic.forum), posts_count=1)
self.assertEqual(topic.forum.count_unanswered_topics, 2)

def test_kind(self):
self.assertEqual(
Forum.kind.field.flatchoices,
[("PUBLIC_FORUM", "Espace public"), ("PRIVATE_FORUM", "Espace privé"), ("NEWS", "Actualités")],
)
50 changes: 11 additions & 39 deletions lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,6 @@ def test_postform_in_context(self):
self.assertIsInstance(response.context_data["form"], PostForm)
self.assertContains(response, f'id="collapsePost{self.topic.pk}')

def test_loadmoretopic_url_in_context(self):
self.client.force_login(self.user)
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertEqual(
response.context_data["loadmoretopic_url"],
reverse(
"forum_conversation_extension:topic_list",
kwargs={"forum_pk": self.forum.pk, "forum_slug": self.forum.slug},
),
)

def test_cannot_submit_post(self):
user = UserFactory()
assign_perm("can_read_forum", user, self.forum)
Expand Down Expand Up @@ -290,44 +278,28 @@ def test_certified_post_display(self):
self.assertContains(response, "Certifié par la Plateforme de l'Inclusion")

def test_loadmoretopic_url(self):
loadmoretopic_url = reverse(
"forum_conversation_extension:topic_list",
kwargs={"forum_pk": self.forum.pk, "forum_slug": self.forum.slug},
)

TopicFactory.create_batch(9, with_post=True, forum=self.forum)
self.client.force_login(self.user)
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertNotContains(
response,
reverse(
"forum_conversation_extension:topic_list",
kwargs={"forum_pk": self.forum.pk, "forum_slug": self.forum.slug},
)
+ "?page=2",
)
self.assertEqual(response.context_data["loadmoretopic_url"], loadmoretopic_url)

self.assertNotContains(response, loadmoretopic_url + "?page=2")

TopicFactory(with_post=True, forum=self.forum)
self.client.force_login(self.user)
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
reverse(
"forum_conversation_extension:topic_list",
kwargs={"forum_pk": self.forum.pk, "forum_slug": self.forum.slug},
)
+ "?page=2",
)
self.assertContains(response, loadmoretopic_url + "?page=2")

TopicFactory.create_batch(10, with_post=True, forum=self.forum)
self.client.force_login(self.user)
response = self.client.get(self.url)
response = self.client.get(self.url + "?page=2")
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
reverse(
"forum_conversation_extension:topic_list",
kwargs={"forum_pk": self.forum.pk, "forum_slug": self.forum.slug},
)
+ "?page=2",
)
self.assertContains(response, loadmoretopic_url + "?page=3")

def test_topic_has_tags(self):
tag = f"tag_{faker.word()}"
Expand Down
3 changes: 1 addition & 2 deletions lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from typing import Any

from django.conf import settings
from django.db.models import Count, Exists, OuterRef
Expand Down Expand Up @@ -63,5 +62,5 @@ class CategoryForumListView(ListView):
template_name = "forum/category_forum_list.html"
context_object_name = "forums"

def get_queryset(self) -> QuerySet[Any]:
def get_queryset(self) -> QuerySet[Forum]:
return Forum.objects.filter(type=Forum.FORUM_CAT, kind=ForumKind.PUBLIC_FORUM, level=0)

0 comments on commit cc343c8

Please sign in to comment.