summaryrefslogtreecommitdiffstats
path: root/tests/test_web.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_web.py')
-rw-r--r--tests/test_web.py29
1 files changed, 28 insertions, 1 deletions
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"</body>" 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