From 51a1738001a29d5ddf7d7eb623dd7a77a00e017c Mon Sep 17 00:00:00 2001 From: Gerrit Vermeulen Date: Wed, 28 Aug 2024 16:17:48 +0200 Subject: [PATCH] Add test for meta data in Pages --- home/tests/test_api.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/home/tests/test_api.py b/home/tests/test_api.py index 8a62e433..eee714e6 100644 --- a/home/tests/test_api.py +++ b/home/tests/test_api.py @@ -505,6 +505,42 @@ def test_detail_view_content(self, uclient, platform): "has_children": False, } + @pytest.mark.parametrize("platform", ALL_PLATFORMS) + def test_detail_view_meta(self, uclient, platform): + """ + Fetching the detail view of a page returns the page metadata. + """ + page = self.create_content_page(tags=["self_help"], body_type=platform) + response = uclient.get(f"/api/v2/pages/{page.id}/") + content = response.json() + + # There's a lot of metadata, so only check selected fields. + meta = content.pop("meta") + parent = page.get_parent() + + assert meta == { + "type": "home.ContentPage", + "detail_url": f"http://localhost/api/v2/pages/{page.id}/", + "html_url": page.get_full_url(), + "slug": page.slug, + "show_in_menus": "false", + "seo_title": page.seo_title, + "search_description": page.search_description, + "first_published_at": page.first_published_at.strftime( + "%Y-%m-%dT%H:%M:%S.%fZ" + ), + "alias_of": page.alias_of, + "parent": { + "id": parent.id, + "meta": { + "type": "home.ContentPageIndex", + "html_url": parent.get_full_url(), + }, + "title": parent.title, + }, + "locale": "en", + } + def test_detail_view_increments_count(self, uclient): """ Fetching the detail view of a page increments the view count.