From 5af5f252ad91a85e94050cf1f3080f7b81c802b0 Mon Sep 17 00:00:00 2001 From: vincent porte Date: Tue, 13 Aug 2024 10:29:13 +0200 Subject: [PATCH] =?UTF-8?q?feat(forum):=C2=A0add=20test=20on=20multiple=20?= =?UTF-8?q?tags?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lacommunaute/forum/tests/tests_views.py | 28 ++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lacommunaute/forum/tests/tests_views.py b/lacommunaute/forum/tests/tests_views.py index 6e0fed41..0d7e679b 100644 --- a/lacommunaute/forum/tests/tests_views.py +++ b/lacommunaute/forum/tests/tests_views.py @@ -671,23 +671,37 @@ def test_documentation_category_foot_content( assert str(add_documentation_control[0]) == snapshot(name="documentation_category_add_file_control") def test_filter_subforums_on_tags(self, client, db): - tag = faker.word() - category_forum = CategoryForumFactory(with_public_perms=True, with_child=True) - second_child = ForumFactory(parent=category_forum, with_public_perms=True, with_tags=[tag]) - third_child = ForumFactory(parent=category_forum, with_public_perms=True) + tags = [faker.word() for _ in range(3)] + category_forum = CategoryForumFactory(with_public_perms=True) + first_child = ForumFactory(parent=category_forum, with_public_perms=True, with_tags=[tags[0]]) + second_child = ForumFactory(parent=category_forum, with_public_perms=True, with_tags=[tags[0], tags[1]]) + third_child = ForumFactory(parent=category_forum, with_public_perms=True, with_tags=[tags[2]]) + # forum without tags + ForumFactory(parent=category_forum, with_public_perms=True) # edge case: grand_child is filtered out. No actual use case to display them in the subforum list - ForumFactory(parent=third_child, with_public_perms=True, with_tags=[tag]) + ForumFactory(parent=third_child, with_public_perms=True, with_tags=[tags[2]]) + # no filter response = client.get(category_forum.get_absolute_url()) assert response.status_code == 200 assert [node.obj for node in response.context_data["sub_forums"].top_nodes] == list( category_forum.get_children() ) - response = client.get(category_forum.get_absolute_url() + f"?forum_tags={tag}") + # filter on first tag + response = client.get(category_forum.get_absolute_url() + f"?forum_tags={tags[0]}") + assert response.status_code == 200 + assert set([node.obj for node in response.context_data["sub_forums"].top_nodes]) == set( + [first_child, second_child] + ) + + # filter on multiple tags + response = client.get(category_forum.get_absolute_url() + f"?forum_tags={tags[1]},{tags[2]}") assert response.status_code == 200 - assert [node.obj for node in response.context_data["sub_forums"].top_nodes] == [second_child] + assert set([node.obj for node in response.context_data["sub_forums"].top_nodes]) == set( + [second_child, third_child] + ) @pytest.fixture(name="discussion_area_forum")