1313@pytest .mark .django_db (True )
1414class TestSearchAPIView :
1515
16- _topics = []
17- _pages = []
18-
1916 @property
2017 def path (self ) -> str :
2118 return "/api/public/search/v1"
@@ -64,7 +61,7 @@ def other_pages(self) -> [UKHSAPage]:
6461 def test_search_finds_topics_only (self , topics , other_pages ):
6562 """
6663 Given a string that matches all topic pages
67- When the GET /api/public/v2/search API is called with that query and a limit of 5
64+ When the API is called with that query and a limit of 5
6865 Then the results will include only topic pages
6966 """
7067
@@ -89,7 +86,32 @@ def test_search_finds_topics_only(self, topics, other_pages):
8986 def test_search_finds_topics_and_pages (self , topics , other_pages ):
9087 """
9188 Given a string that matches 2 topic page
92- When GET /api/public/v2/search is called with that query and no limit
89+ When the API is called with that query and no limit
90+ Then the results will include the matching topic pages and others with the topics first
91+ """
92+
93+ # Given
94+ search = "rare" # All topics have a title, only even ones have rare in it
95+ query = f"search={ search } "
96+ expected_results = [t for t in topics if "rare" in t .title ]
97+
98+ # When
99+ client = RequestsClient ()
100+ url = f"{ self .target_domain } { self .path } ?{ query } "
101+ response : Response = client .get (url )
102+
103+ # Then
104+ assert response .status_code == HTTPStatus .OK
105+ response_data : list [dict ] = response .json ()
106+ assert len (expected_results ) == len (response_data )
107+ for page in expected_results :
108+ target = {"title" : page .title , "slug" : page .slug }
109+ assert response_data .index (target ) > - 1
110+
111+ def test_search_doesnt_find_unpublish_pages (self , topics , other_pages ):
112+ """
113+ Given a string that matches 2 topic page
114+ When the API is called with that query and no limit
93115 Then the results will include the matching topic pages and others with the topics first
94116 """
95117
0 commit comments