Skip to content

Commit

Permalink
wip fixing existing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Jun 29, 2023
1 parent ecccdc9 commit 5da6a3b
Show file tree
Hide file tree
Showing 13 changed files with 73 additions and 297 deletions.
7 changes: 4 additions & 3 deletions lacommunaute/forum/tests/test_CategoryForumListView.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import pytest # noqa
from django.urls import reverse

from lacommunaute.forum.enums import Kind as ForumKind
from lacommunaute.forum.factories import ForumFactory
from lacommunaute.forum.models import Forum


def test_context(client, db):
url = reverse("forum_extension:categories")
url = reverse("forum_extension:documentation")
response = client.get(url)
assert response.status_code == 200
assert "forum/category_forum_list.html" == response.templates[0].name
Expand All @@ -17,11 +18,11 @@ def test_queryset(client, db):
forum = ForumFactory(type=Forum.FORUM_CAT)
unvisible_forums = (
ForumFactory(type=Forum.FORUM_CAT, parent=forum),
ForumFactory(type=Forum.FORUM_CAT, is_private=True),
ForumFactory(type=Forum.FORUM_CAT, kind=ForumKind.PRIVATE_FORUM),
ForumFactory(),
ForumFactory(type=Forum.FORUM_LINK),
)
url = reverse("forum_extension:categories")
url = reverse("forum_extension:documentation")
response = client.get(url)
assert response.status_code == 200
assert forum in response.context_data["forums"]
Expand Down
2 changes: 1 addition & 1 deletion lacommunaute/forum/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def test_cannot_submit_post(self):
def test_queries(self):
TopicFactory.create_batch(20, with_post=True)
self.client.force_login(self.user)
with self.assertNumQueries(33):
with self.assertNumQueries(27):
self.client.get(self.url)

def test_certified_post_display(self):
Expand Down
3 changes: 2 additions & 1 deletion lacommunaute/forum/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from machina.apps.forum.views import ForumView as BaseForumView
from machina.core.loading import get_class

from lacommunaute.forum.enums import Kind as ForumKind
from lacommunaute.forum.models import Forum
from lacommunaute.forum_conversation.forms import PostForm
from lacommunaute.forum_conversation.models import Topic
Expand Down Expand Up @@ -63,4 +64,4 @@ class CategoryForumListView(ListView):
context_object_name = "forums"

def get_queryset(self) -> QuerySet[Any]:
return Forum.objects.filter(type=Forum.FORUM_CAT, level=0)
return Forum.objects.filter(type=Forum.FORUM_CAT, kind=ForumKind.PUBLIC_FORUM, level=0)
7 changes: 6 additions & 1 deletion lacommunaute/forum_conversation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

class TopicQuerySet(models.QuerySet):
def unanswered(self):
return self.exclude(approved=False).exclude(status=Topic.TOPIC_LOCKED).filter(posts_count=1)
return (
self.exclude(approved=False)
.exclude(status=Topic.TOPIC_LOCKED)
.exclude(type=Topic.TOPIC_ANNOUNCE)
.filter(posts_count=1)
)

def optimized_for_topics_list(self, user_id):
return (
Expand Down
4 changes: 1 addition & 3 deletions lacommunaute/forum_conversation/tests/tests_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def test_unanswered(self):
TopicFactory(forum=forum, posts_count=1, type=Topic.TOPIC_ANNOUNCE)
TopicFactory(forum=forum, posts_count=1, approved=False)

self.assertEqual(Topic.objects.unanswered().count(), 1)
self.assertIn(topic, Topic.objects.unanswered())
self.assertEqual(Topic.objects.unanswered().get(), topic)

def test_optimized_for_topics_list_disapproved(self):
TopicFactory(approved=False)
Expand Down Expand Up @@ -125,4 +124,3 @@ def test_topic_types(self):
self.assertEqual(0, Topic.TOPIC_POST)
self.assertEqual(1, Topic.TOPIC_STICKY)
self.assertEqual(2, Topic.TOPIC_ANNOUNCE)
self.assertEqual(3, Topic.TOPIC_NEWS)
Loading

0 comments on commit 5da6a3b

Please sign in to comment.