From 47d850df7f9ad6a29485691b0d576035e25302be Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 23 Oct 2020 00:38:28 -0700 Subject: basic web search test --- tests/test_web.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'tests/test_web.py') diff --git a/tests/test_web.py b/tests/test_web.py index 39b5f22..3c7e423 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -1,5 +1,8 @@ -import pytest + +import json from typing import Any + +import pytest from fastapi.testclient import TestClient from fatcat_scholar.web import app @@ -57,3 +60,27 @@ def test_basic_routes(client: Any) -> None: resp = client.get(lang + path) assert resp.status_code == 200 assert b"" in resp.content + + +def test_basic_search(client: Any, mocker: Any) -> None: + + rv = client.get("/search") + assert rv.status_code == 200 + + with open("tests/files/elastic_fulltext_search.json") as f: + elastic_resp = json.loads(f.read()) + + es_raw = mocker.patch( + "elasticsearch.connection.Urllib3HttpConnection.perform_request" + ) + es_raw.side_effect = [ + (200, {}, json.dumps(elastic_resp)), + (200, {}, json.dumps(elastic_resp)), + ] + + rv = client.get("/search?q=blood") + assert rv.status_code == 200 + assert b"Hits" in rv.content + + rv = client.get("/zh/search?q=blood") + assert rv.status_code == 200 -- cgit v1.2.3