Skip to content

Commit

Permalink
Test a simple search query
Browse files Browse the repository at this point in the history
  • Loading branch information
mgax committed Nov 29, 2023
1 parent c77347a commit 5d2fb02
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions ietf/search/tests.py
Original file line number Diff line number Diff line change
@@ -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": "<p>blog body</p>"}]',
)
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)],
)

0 comments on commit 5d2fb02

Please sign in to comment.