summaryrefslogtreecommitdiffstats
path: root/tests/test_web.py
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-10-23 00:38:28 -0700
committerBryan Newbold <bnewbold@archive.org>2020-10-23 00:38:28 -0700
commit47d850df7f9ad6a29485691b0d576035e25302be (patch)
tree6b5695de916c1bd97ce17afdb5b9b67c94aa3482 /tests/test_web.py
parentcb35d6a0fb3962281f074ef09360b47dc69e481d (diff)
downloadfatcat-scholar-47d850df7f9ad6a29485691b0d576035e25302be.tar.gz
fatcat-scholar-47d850df7f9ad6a29485691b0d576035e25302be.zip
basic web search test
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