From f905b95b643993d10c7f15cc0e9df3b986e7178b Mon Sep 17 00:00:00 2001 From: vincent porte Date: Wed, 7 Aug 2024 12:46:50 +0200 Subject: [PATCH] upgrade homepage test --- .../tests/__snapshots__/test_homepage.ambr | 286 ++++++++++++++++++ lacommunaute/pages/tests/test_homepage.py | 19 +- 2 files changed, 303 insertions(+), 2 deletions(-) create mode 100644 lacommunaute/pages/tests/__snapshots__/test_homepage.ambr diff --git a/lacommunaute/pages/tests/__snapshots__/test_homepage.ambr b/lacommunaute/pages/tests/__snapshots__/test_homepage.ambr new file mode 100644 index 000000000..f5dea19e9 --- /dev/null +++ b/lacommunaute/pages/tests/__snapshots__/test_homepage.ambr @@ -0,0 +1,286 @@ +# serializer version: 1 +# name: test_page_title_header_footer[homepage_footer] + ''' + + ''' +# --- +# name: test_page_title_header_footer[homepage_header] + ''' + + ''' +# --- +# name: test_page_title_header_footer[homepage_title] + ''' + + Accueil - La communauté de l'inclusion + + ''' +# --- diff --git a/lacommunaute/pages/tests/test_homepage.py b/lacommunaute/pages/tests/test_homepage.py index 2b3851644..ca4cf481a 100644 --- a/lacommunaute/pages/tests/test_homepage.py +++ b/lacommunaute/pages/tests/test_homepage.py @@ -1,3 +1,5 @@ +import re + import pytest # noqa from dateutil.relativedelta import relativedelta from django.urls import reverse @@ -8,6 +10,11 @@ from lacommunaute.forum.enums import Kind as ForumKind from lacommunaute.forum.factories import ForumFactory from lacommunaute.forum_conversation.factories import PostFactory, TopicFactory +from lacommunaute.utils.testing import parse_response_to_soup + + +def _sub_svg_suffix(content): + return re.sub(r"\.\w+\.svg", ".svg", content) def test_context_data(client, db): @@ -44,9 +51,17 @@ def test_new_topics_order(client, db): assert list(response.context_data["topics_public"]) == [topic2, topic1] -def test_page_title(db, client): +def test_page_title_header_footer(db, client, snapshot): response = client.get(reverse("pages:home")) - assertContains(response, "Accueil- La communauté de l'inclusion", html=True, count=1) + assert response.status_code == 200 + + assert str(parse_response_to_soup(response, selector="title")) == snapshot(name="homepage_title") + + header = _sub_svg_suffix(str(parse_response_to_soup(response, selector="header"))) + assert header == snapshot(name="homepage_header") + + footer = _sub_svg_suffix(str(parse_response_to_soup(response, selector="footer"))) + assert footer == snapshot(name="homepage_footer") def test_events(db, client):