diff --git a/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr b/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr new file mode 100644 index 000000000..ec18cc9a2 --- /dev/null +++ b/lacommunaute/forum_conversation/tests/__snapshots__/tests_views.ambr @@ -0,0 +1,46 @@ +# serializer version: 1 +# name: TestPosterTemplate.test_topic_from_other_public_forum_in_topics_view[topic_from_other_public_forum_in_topics_view] + ''' + + Par : + + + + Alan T. + , + + + dans Abby's Forum, + il y a 0 minute + + + ''' +# --- +# name: TestPosterTemplate.test_topic_in_its_own_public_forum[topic_in_its_own_public_forum] + ''' + + Par : + + + + Dermot T. + , + il y a 0 minute + + + ''' +# --- +# name: TestPosterTemplate.test_topic_in_topics_view[topic_in_topics_view] + ''' + + Par : + + + + Jeff B. + , + il y a 0 minute + + + ''' +# --- diff --git a/lacommunaute/forum_conversation/tests/tests_views.py b/lacommunaute/forum_conversation/tests/tests_views.py index a75e1f869..37a908627 100644 --- a/lacommunaute/forum_conversation/tests/tests_views.py +++ b/lacommunaute/forum_conversation/tests/tests_views.py @@ -28,6 +28,7 @@ from lacommunaute.forum_moderation.factories import BlockedDomainNameFactory, BlockedEmailFactory from lacommunaute.forum_upvote.factories import UpVoteFactory from lacommunaute.users.factories import UserFactory +from lacommunaute.utils.testing import parse_response_to_soup faker = Faker(settings.LANGUAGE_CODE) @@ -834,6 +835,56 @@ def test_template_name(self): self.assertTemplateUsed(response, "forum_conversation/topic_list.html") +class TestPosterTemplate: + def test_topic_in_topics_view(self, client, db, snapshot): + topic = TopicFactory(with_post=True, poster=UserFactory(first_name="Jeff", last_name="Buckley")) + response = client.get(reverse("forum_conversation_extension:topics")) + 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): + # first_public_forum + ForumFactory(with_public_perms=True) + + topic = TopicFactory( + with_post=True, + 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")) + soup = parse_response_to_soup( + response, + replace_in_href=[ + (topic.poster.username, "poster_username"), + ( + reverse("forum_extension:forum", kwargs={"slug": topic.forum.slug, "pk": topic.forum.pk}), + "forum_url", + ), + ], + selector=".poster-infos", + ) + assert str(soup) == snapshot(name="topic_from_other_public_forum_in_topics_view") + + def test_topic_in_its_own_public_forum(self, client, db, snapshot): + # first_public_forum + ForumFactory(with_public_perms=True) + + topic = TopicFactory( + with_post=True, + forum=ForumFactory(with_public_perms=True, name="Joe's Forum"), + poster=UserFactory(first_name="Dermot", last_name="Turing"), + ) + response = client.get( + reverse("forum_extension:forum", kwargs={"slug": topic.forum.slug, "pk": topic.forum.pk}) + ) + soup = parse_response_to_soup( + response, replace_in_href=[(topic.poster.username, "poster_username")], selector=".poster-infos" + ) + assert str(soup) == snapshot(name="topic_in_its_own_public_forum") + + class NewsFeedTopicListViewTest(TestCase): @classmethod def setUpTestData(cls): diff --git a/lacommunaute/templates/forum_conversation/partials/poster.html b/lacommunaute/templates/forum_conversation/partials/poster.html index 99bb43068..22aa3ab10 100644 --- a/lacommunaute/templates/forum_conversation/partials/poster.html +++ b/lacommunaute/templates/forum_conversation/partials/poster.html @@ -5,7 +5,7 @@ {% load forum_permission_tags %} {% get_permission 'can_edit_post' post request.user as user_can_edit_post %} {% endif %} - + {% spaceless %} {% with poster=post.poster_display_name %} Par : @@ -17,6 +17,9 @@ {% else %} {{ poster }}, {% endif %} + {% if forum and forum != topic.forum %} + dans {{ topic.forum }}, + {% endif %} {% endwith %} {% endspaceless %} {{ post.created|relativetimesince_fr }} diff --git a/lacommunaute/templates/forum_conversation/topic_list.html b/lacommunaute/templates/forum_conversation/topic_list.html index 1dd7fdd05..e565853c6 100644 --- a/lacommunaute/templates/forum_conversation/topic_list.html +++ b/lacommunaute/templates/forum_conversation/topic_list.html @@ -42,13 +42,10 @@
- {% include "forum_conversation/partials/poster.html" with post=topic.first_post topic=topic is_topic_head=True %} + {% include "forum_conversation/partials/poster.html" with post=topic.first_post topic=topic is_topic_head=True forum=forum %}
{% include "forum_conversation/partials/topic_tags.html" with tags=topic.tags.all %} - {% if forum != topic.forum %} - {{ topic.forum }} - {% endif %}