-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: filtrage des questions en utilisant les étiquettes #794
Merged
+357
−263
Merged
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
844ce4d
deambiguate active_tag, since it is not a queryset but a single objec…
vincentporte 27717b1
enhance test_queryset_for_tagged_topic using parametrize
vincentporte 5cce648
remove page=1 param, which make filters be hidden
vincentporte 1181bc3
reuse topics_url fixture in TopicListView tests, and enhance test_cli…
vincentporte aa21a73
call TopicListView in HX-Request mode (HTMX) to prevent page scrolling
vincentporte 26ce8ee
rename Filters enums
vincentporte a088660
simplify active_filter to get name and value at once
vincentporte 437f604
add answered post_generation method to Topic Factory
vincentporte dd90aad
rewrite last TopicListView from unittest to pytest style
vincentporte d61afd3
add current filter being displayed
vincentporte File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
from faker import Faker | ||
from machina.core.db.models import get_model | ||
from machina.core.loading import get_class | ||
|
||
from pytest_django.asserts import assertContains, assertNotContains | ||
from taggit.models import Tag | ||
|
||
|
@@ -770,34 +769,36 @@ def test_numqueries(self): | |
self.assertEqual(response.status_code, 200) | ||
|
||
|
||
@pytest.fixture(name="topics_url") | ||
def fixture_topics_url(): | ||
return reverse("forum_conversation_extension:topics") | ||
|
||
|
||
@pytest.mark.parametrize("tag", ["lower", "UPPER"]) | ||
def test_queryset_filtered_on_tag(client, db, tag): | ||
def test_queryset_filtered_on_tag(client, db, tag, topics_url): | ||
forum = ForumFactory(with_public_perms=True) | ||
other_topic = TopicFactory(with_post=True, forum=forum) | ||
tagged_topic = TopicFactory(with_post=True, forum=forum, with_tags=[tag]) | ||
|
||
response = client.get(reverse("forum_conversation_extension:topics"), data={"tags": tag}) | ||
response = client.get(topics_url, data={"tag": tag}) | ||
assert response.context_data["paginator"].count == 1 | ||
assertContains(response, tagged_topic.subject) | ||
assertNotContains(response, other_topic.subject) | ||
|
||
|
||
def test_queryset_for_tagged_topic(client, db, snapshot): | ||
@pytest.mark.parametrize("num_of_tagged_topics", [1, 2]) | ||
def test_queryset_for_tagged_topic(client, db, num_of_tagged_topics, topics_url, snapshot): | ||
tags = ["buckley", "jeff"] | ||
tagged_topic = TopicFactory(with_post=True, with_tags=tags) | ||
tagged_topics = TopicFactory.create_batch(num_of_tagged_topics, with_post=True, with_tags=tags) | ||
untagged_topic = TopicFactory(with_post=True) | ||
|
||
response = client.get(reverse("forum_conversation_extension:topics"), {"tags": tags[0]}) | ||
response = client.get(topics_url, {"tag": tags[0]}) | ||
content = parse_response_to_soup(response, selector="#topic-list-filter-header") | ||
assert str(content) == snapshot(name="tagged_topic") | ||
assertContains(response, tagged_topic.subject) | ||
assert str(content) == snapshot(name=f"{num_of_tagged_topics}-tagged_topics") | ||
for tagged_topic in tagged_topics: | ||
assertContains(response, tagged_topic.subject) | ||
assertNotContains(response, untagged_topic.subject) | ||
|
||
TopicFactory(with_post=True, with_tags=tags) | ||
response = client.get(reverse("forum_conversation_extension:topics"), {"tags": tags[0]}) | ||
content = parse_response_to_soup(response, selector="#topic-list-filter-header") | ||
assert str(content) == snapshot(name="tagged_topics") | ||
|
||
|
||
def test_breadcrumbs_on_topic_view(client, db, snapshot): | ||
discussion_area_forum = ForumFactory(with_public_perms=True) | ||
|
@@ -875,7 +876,7 @@ def test_context(self): | |
self.assertEqual(response.context_data["loadmoretopic_url"], reverse("forum_conversation_extension:topics")) | ||
self.assertEqual(response.context_data["forum"], self.forum) | ||
self.assertEqual(response.context_data["active_filter_name"], Filters.ALL.label) | ||
self.assertEqual(response.context_data["active_tags"], "") | ||
self.assertEqual(list(response.context_data["active_tag"]), []) | ||
|
||
for filter, label in Filters.choices: | ||
with self.subTest(filter=filter, label=label): | ||
|
@@ -891,9 +892,9 @@ def test_context(self): | |
|
||
def test_context_with_tag(self): | ||
tags = [Tag.objects.create(name=faker.sentence()) for i in range(2)] | ||
response = self.client.get(self.url, {"tags": ",".join([tag.slug for tag in tags])}) | ||
self.assertEqual(response.context_data["active_tags"], ",".join([tag.slug for tag in tags])) | ||
self.assertEqual(response.context_data["active_tags_label"], " ou ".join([tag.name for tag in tags])) | ||
for tag in tags: | ||
response = self.client.get(self.url, {"tag": tag.slug}) | ||
self.assertEqual(response.context_data["active_tag"], tag) | ||
|
||
def test_queryset(self): | ||
response = self.client.get(self.url) | ||
|
@@ -976,13 +977,6 @@ def test_filter_dropdown_visibility(self): | |
self.assertNotContains(response, '<div class="dropdown-menu dropdown-menu-end" id="filterTopicsDropdown">') | ||
self.assertEqual(response.context_data["filter_dropdown_endpoint"], None) | ||
|
||
def test_filter_dropdown_with_tags(self): | ||
tag = Tag.objects.create(name=faker.words(nb=3)) | ||
response = self.client.get(self.url + f"?tags={tag.slug}") | ||
self.assertContains(response, f'hx-get="/topics/?filter=ALL&tags={tag.slug}"') | ||
self.assertContains(response, f'hx-get="/topics/?filter=NEW&tags={tag.slug}"') | ||
self.assertContains(response, f'hx-get="/topics/?filter=CERTIFIED&tags={tag.slug}"') | ||
|
||
def test_template_name(self): | ||
response = self.client.get(self.url) | ||
self.assertTemplateUsed(response, "forum_conversation/topics_public.html") | ||
|
@@ -991,33 +985,49 @@ def test_template_name(self): | |
self.assertTemplateUsed(response, "forum_conversation/topic_list.html") | ||
|
||
|
||
@pytest.fixture(name="public_forum_with_topic") | ||
def fixture_public_forum_with_topic(db): | ||
forum = ForumFactory(with_public_perms=True) | ||
TopicFactory(with_post=True, forum=forum, with_tags=["tag"]) | ||
return forum | ||
|
||
|
||
class TestTopicListView: | ||
def test_clickable_tags(self, client, db, snapshot): | ||
@pytest.mark.parametrize( | ||
"num_of_topics_before_tagged_topic,query_param,snapshot_name", | ||
[(None, None, "clickable_tags_page1"), (10, "?page=2", "clickable_tags_page2")], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pour te faciliter la vie, tu pourrais définir les query params vide avec "". 🤷 |
||
) | ||
def test_clickable_tags( | ||
self, client, db, topics_url, num_of_topics_before_tagged_topic, query_param, snapshot_name, snapshot | ||
): | ||
forum = ForumFactory(with_public_perms=True) | ||
|
||
TopicFactory(with_post=True, forum=forum, with_tags=["tag"]) | ||
if num_of_topics_before_tagged_topic: | ||
# add 10 Topics before the tagged one to put it on the second page | ||
TopicFactory.create_batch(num_of_topics_before_tagged_topic, with_post=True, forum=forum) | ||
|
||
response = client.get(reverse("forum_conversation_extension:topics")) | ||
url = topics_url + query_param if query_param else topics_url | ||
response = client.get(url) | ||
assert response.status_code == 200 | ||
assert str(parse_response_to_soup(response, selector="a.tag")) == snapshot(name="clickable_tags_page1") | ||
|
||
# add 10 Topics before the tagged one to put it on the second page | ||
TopicFactory.create_batch(10, with_post=True, forum=forum) | ||
assert str(parse_response_to_soup(response, selector="#filtertopics-button")) == snapshot(name=snapshot_name) | ||
|
||
response = client.get(reverse("forum_conversation_extension:topics") + "?page=2") | ||
assert response.status_code == 200 | ||
assert str(parse_response_to_soup(response, selector="a.tag")) == snapshot(name="clickable_tags_page2") | ||
def test_filter_dropdown_with_tags(self, client, db, public_forum_with_topic, topics_url, snapshot): | ||
response = client.get(topics_url + "?tag=tag") | ||
content = parse_response_to_soup(response, selector="#filterTopicsDropdown") | ||
assert str(content) == snapshot(name="filter_dropdown_with_tags") | ||
|
||
|
||
class TestPosterTemplate: | ||
def test_topic_in_topics_view(self, client, db, snapshot): | ||
def test_topic_in_topics_view(self, client, db, topics_url, snapshot): | ||
topic = TopicFactory(with_post=True, poster=UserFactory(first_name="Jeff", last_name="Buckley")) | ||
response = client.get(reverse("forum_conversation_extension:topics")) | ||
response = client.get(topics_url) | ||
soup = parse_response_to_soup( | ||
response, replace_in_href=[(topic.poster.username, "poster_username")], selector=".poster-infos" | ||
) | ||
assert str(soup) == snapshot(name="topic_in_topics_view") | ||
|
||
def test_topic_from_other_public_forum_in_topics_view(self, client, db, snapshot): | ||
def test_topic_from_other_public_forum_in_topics_view(self, client, db, topics_url, snapshot): | ||
# first_public_forum | ||
ForumFactory(with_public_perms=True) | ||
|
||
|
@@ -1026,7 +1036,7 @@ def test_topic_from_other_public_forum_in_topics_view(self, client, db, snapshot | |
forum=ForumFactory(with_public_perms=True, name="Abby's Forum"), | ||
poster=UserFactory(first_name="Alan", last_name="Turing"), | ||
) | ||
response = client.get(reverse("forum_conversation_extension:topics")) | ||
response = client.get(topics_url) | ||
soup = parse_response_to_soup( | ||
response, | ||
replace_in_href=[ | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Laisser un
a
permettrait d’ouvrir les pages dans des onglets.