コード例 #1
0
 def test_search_view_all_items(self):
     self.chapters_test_data.create_chapter(1)
     self.chapters_test_data.create_chapter(2)
     self.chapters_test_data.create_chapter(3)
     management.call_command("rebuild_index", "--noinput")
     url = reverse("search:index")
     get_parameters = [("q", "")]
     url += query_string(get_parameters)
     response = self.client.get(url)
     self.assertEqual(len(response.context["object_list"]), 0)
コード例 #2
0
 def test_search_view_model_filter(self):
     chapter = self.chapters_test_data.create_chapter(1)
     self.chapters_test_data.create_chapter_section(chapter, 1)
     management.call_command("rebuild_index", "--noinput")
     url = reverse("search:index")
     get_parameters = [
         ("models", "chapters.chapter"),
         ("q", "chapter"),
     ]
     url += query_string(get_parameters)
     response = self.client.get(url)
     result_objects = response.context["object_list"]
     self.assertEqual(len(result_objects), 1)
     self.assertEqual(result_objects[0].model_name, "chapter")
コード例 #3
0
 def test_search_view_context_model_data_with_selected(self):
     management.call_command("rebuild_index", "--noinput")
     url = reverse("search:index")
     get_parameters = [
         ("models", "chapters.chapter"),
     ]
     url += query_string(get_parameters)
     response = self.client.get(url)
     self.assertEqual(response.context["models"], [
         {
             "value": "chapters.chaptersection",
             "name": "Chapter sections",
         },
         {
             "value": "chapters.chapter",
             "selected": "true",
             "name": "Chapters"
         },
     ])