aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-10-22 20:17:34 -0700
committerBryan Newbold <bnewbold@archive.org>2020-10-22 20:17:34 -0700
commit06e1e58110da1ed6c43ce740433ba7234b56d981 (patch)
treec2ccb0f55c277d93aa3a94316631621505cf16c5 /tests
parent498677bbe0a04af2ca527bdff83d02bb0710dac9 (diff)
downloadfatcat-scholar-06e1e58110da1ed6c43ce740433ba7234b56d981.tar.gz
fatcat-scholar-06e1e58110da1ed6c43ce740433ba7234b56d981.zip
start test coverage for web interface
Diffstat (limited to 'tests')
-rw-r--r--tests/test_web.py59
-rw-r--r--tests/test_web_search.py9
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/test_web.py b/tests/test_web.py
new file mode 100644
index 0000000..39b5f22
--- /dev/null
+++ b/tests/test_web.py
@@ -0,0 +1,59 @@
+import pytest
+from typing import Any
+from fastapi.testclient import TestClient
+
+from fatcat_scholar.web import app
+
+
+@pytest.fixture
+def client() -> TestClient:
+ return TestClient(app)
+
+
+def test_main_view(client: Any) -> None:
+ resp = client.get("/")
+ assert resp.status_code == 200
+ assert b"Internet Archive Scholar" in resp.content
+
+ resp = client.get("/ar/")
+ assert resp.status_code == 200
+ assert "معلومات عن" in resp.content.decode("utf-8")
+
+ resp = client.get("/", headers={"Accept-Language": "ar"})
+ assert resp.status_code == 200
+ assert "معلومات عن" in resp.content.decode("utf-8")
+
+
+def test_basic_api(client: Any) -> None:
+ """
+ Simple check of GET routes with application/json support
+ """
+ headers = {"Accept": "application/json"}
+ resp = client.get("/", headers=headers)
+ assert resp.status_code == 200
+ assert resp.json()
+
+ resp = client.get("/search", headers=headers)
+ assert resp.status_code == 200
+ assert resp.json()
+
+
+def test_basic_routes(client: Any) -> None:
+ """
+ Simple check of GET routes in the web app
+ """
+
+ resp = client.get("/robots.txt")
+ assert resp.status_code == 200
+
+ resp = client.get("/static/ia-logo.svg")
+ assert resp.status_code == 200
+
+ LANG_PREFIX_LIST = ["", "/ar"]
+ PATH_LIST = ["/", "/about", "/help", "/search"]
+
+ for lang in LANG_PREFIX_LIST:
+ for path in PATH_LIST:
+ resp = client.get(lang + path)
+ assert resp.status_code == 200
+ assert b"</body>" in resp.content
diff --git a/tests/test_web_search.py b/tests/test_web_search.py
new file mode 100644
index 0000000..e883325
--- /dev/null
+++ b/tests/test_web_search.py
@@ -0,0 +1,9 @@
+from elasticsearch_dsl import Search
+
+from fatcat_scholar.search import FulltextQuery, apply_filters
+
+
+def test_apply_filters() -> None:
+ search = Search()
+ query = FulltextQuery()
+ apply_filters(search, query)