fix club detail on ClubView

This commit is contained in:
Thomas Girod 2025-04-04 14:26:19 +02:00
parent 056b3a1702
commit 89efda6e26
2 changed files with 40 additions and 0 deletions

39
club/tests/test_page.py Normal file
View File

@ -0,0 +1,39 @@
import pytest
from bs4 import BeautifulSoup
from django.test import Client
from django.urls import reverse
from model_bakery import baker
from pytest_django.asserts import assertHTMLEqual
from club.models import Club
from core.markdown import markdown
from core.models import PageRev, User
@pytest.mark.django_db
def test_page_display_on_club_main_page(client: Client):
"""Test the club Page is properly displayed on the club main view"""
club = baker.make(Club)
content = "# foo\nLorem ipsum dolor sit amet"
baker.make(PageRev, page=club.page, revision=1, content=content)
client.force_login(baker.make(User))
res = client.get(reverse("club:club_view", kwargs={"club_id": club.id}))
assert res.status_code == 200
soup = BeautifulSoup(res.content.decode(), "lxml")
detail_html = soup.find(id="club_detail").find(class_="markdown")
assertHTMLEqual(detail_html.decode_contents(), markdown(content))
@pytest.mark.django_db
def test_club_main_page_without_content(client: Client):
"""Test the club view works, even if the club page is empty"""
club = baker.make(Club)
club.page.revisions.all().delete()
client.force_login(baker.make(User))
res = client.get(reverse("club:club_view", kwargs={"club_id": club.id}))
assert res.status_code == 200
soup = BeautifulSoup(res.content.decode(), "lxml")
detail_html = soup.find(id="club_detail")
assert detail_html.find_all("markdown") == []

View File

@ -185,6 +185,7 @@ class ClubView(ClubTabsMixin, DetailView):
kwargs["page_revision"] = (
PageRev.objects.filter(page_id=self.object.page_id)
.order_by("-date")
.values_list("content", flat=True)
.first()
)
return kwargs