Skip to content

Commit

Permalink
associate Topics with Document when migrating Forum
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentporte committed Oct 2, 2024
1 parent 53018fd commit a8aa882
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,49 @@
# serializer version: 1
# name: TestPosterTemplate.test_standalone_topic[False-without_document][without_document]
'''
<small class="text-muted poster-infos">
Par :


<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="member" href="/members/profile/poster_username/">
Jeff B.
</a>,
il y a 0 minute

</small>
'''
# ---
# name: TestPosterTemplate.test_standalone_topic[True-with_document][with_document]
'''
<small class="text-muted poster-infos">
Par :


<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="member" href="/members/profile/poster_username/">
Jeff B.
</a>,


dans <a href="[Document absolute URL]">Test Document</a>,
il y a 0 minute

</small>
'''
# ---
# name: TestPosterTemplate.test_standalone_topic[standalone_topic]
'''
<small class="text-muted poster-infos">
Par :


<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="member" href="/members/profile/poster_username/">
Jeff B.
</a>,
il y a 0 minute

</small>
'''
# ---
# name: TestPosterTemplate.test_topic_from_other_public_forum_in_topics_view[topic_from_other_public_forum_in_topics_view]
'''
<small class="text-muted poster-infos">
Expand Down Expand Up @@ -44,6 +89,23 @@
</small>
'''
# ---
# name: TestPosterTemplate.test_topic_with_document[topic_with_document]
'''
<small class="text-muted poster-infos">
Par :


<a class="matomo-event" data-matomo-action="view" data-matomo-category="engagement" data-matomo-option="member" href="/members/profile/poster_username/">
Jeff B.
</a>,


dans <a href="[Document absolute URL]">Test Document</a>,
il y a 0 minute

</small>
'''
# ---
# name: TestTopicCreateCheckView.test_get_method[topic_create_check]
'''
<main class="s-main" id="main" role="main">
Expand Down
62 changes: 16 additions & 46 deletions lacommunaute/forum_conversation/tests/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pytest_django.asserts import assertContains, assertNotContains
from taggit.models import Tag

from lacommunaute.documentation.factories import DocumentFactory
from lacommunaute.forum.factories import CategoryForumFactory, ForumFactory
from lacommunaute.forum_conversation.enums import Filters
from lacommunaute.forum_conversation.factories import (
Expand Down Expand Up @@ -1009,53 +1010,22 @@ def test_clickable_tags(self, client, db, snapshot):


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"))
@pytest.mark.parametrize("with_document,snaphot_name", [(True, "with_document"), (False, "without_document")])
def test_standalone_topic(self, client, db, with_document, snaphot_name, snapshot):
poster = UserFactory(first_name="Jeff", last_name="Buckley")
if with_document:
document = DocumentFactory(for_snapshot=True)
TopicFactory(with_post=True, document=document, poster=poster)
replace_in_href = [
(poster.username, "poster_username"),
(document.get_absolute_url(), "[Document absolute URL]"),
]
else:
TopicFactory(with_post=True, poster=poster)
replace_in_href = [(poster.username, "poster_username")]
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")
soup = parse_response_to_soup(response, replace_in_href=replace_in_href, selector=".poster-infos")
assert str(soup) == snapshot(name=snaphot_name)


class TestTopicCreateCheckView:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
{% else %}
{{ poster }},
{% endif %}
{% if forum and forum != topic.forum %}
dans <a href="{% url 'forum_extension:forum' topic.forum.slug topic.forum.pk %}">{{ topic.forum }}</a>,
{% if topic.document %}
dans <a href="{% url 'documentation:document_detail' topic.document.category.id topic.document.slug topic.document.pk %}">{{ topic.document }}</a>,
{% endif %}
{% endwith %}
{% endspaceless %}
Expand Down

0 comments on commit a8aa882

Please sign in to comment.