Skip to content

Commit f71e309

Browse files
committed
fixup
1 parent 5f72a3a commit f71e309

2 files changed

Lines changed: 28 additions & 6 deletions

File tree

public_api/version_02/views/search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def get(self, request: Request):
2121
limit = int(request.GET.get("limit", 0))
2222
fields = request.GET.get("fields", ["title", "slug"])
2323
meta = request.GET.get("meta", ["id"])
24-
topic_results = TopicPage.objects.all().search(search)
24+
topic_results = TopicPage.objects.live().search(search)
2525
if not limit or topic_results.count() < limit:
2626
# TODO: go get more
2727
# results = queryset

tests/integration/public_api/v2/views/test_search.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
@pytest.mark.django_db(True)
1414
class 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

Comments
 (0)