From 5d2fb025117cb450e89ca176a9632df8a6bab019 Mon Sep 17 00:00:00 2001 From: Alex Morega Date: Tue, 28 Nov 2023 16:58:19 +0200 Subject: [PATCH] Test a simple search query --- ietf/search/tests.py | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 ietf/search/tests.py diff --git a/ietf/search/tests.py b/ietf/search/tests.py new file mode 100644 index 00000000..98e82a51 --- /dev/null +++ b/ietf/search/tests.py @@ -0,0 +1,58 @@ +from django.test import TestCase +from django.urls import reverse +from wagtail.models import Page, Site + +from ..blog.models import BlogIndexPage, BlogPage +from ..home.models import HomePage + + +class SearchTests(TestCase): + def test_search(self): + + root = Page.get_first_root_node() + + home = HomePage( + slug="homepageslug", + title="home page title", + heading="home page heading", + introduction="home page introduction", + request_for_comments_section_body="rfc section body", + working_groups_section_body="wg section body", + ) + + root.add_child(instance=home) + + Site.objects.all().delete() + + Site.objects.create( + hostname="localhost", + root_page=home, + is_default_site=True, + site_name="testingsitename", + ) + + blogindex = BlogIndexPage( + slug="blog", + title="blog index title", + ) + home.add_child(instance=blogindex) + + blog = BlogPage( + slug="blogpost", + title="blog title", + introduction="blog introduction", + body='[{"id": "1", "type": "rich_text", "value": "

blog body

"}]', + ) + blogindex.add_child(instance=blog) + + home.button_text = "blog button text" + home.button_link = blog + home.save() + + resp = self.client.get(f"{reverse('search')}?query=introduction") + + self.assertEqual(resp.context["search_query"], "introduction") + self.assertEqual( + list(resp.context["search_results"]), + [Page.objects.get(pk=blog.pk)], + )