aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fatcat_scholar/web.py2
-rw-r--r--tests/test_web.py6
2 files changed, 7 insertions, 1 deletions
diff --git a/fatcat_scholar/web.py b/fatcat_scholar/web.py
index 124e269..31ee617 100644
--- a/fatcat_scholar/web.py
+++ b/fatcat_scholar/web.py
@@ -97,6 +97,8 @@ class HitsModel(BaseModel):
@api.get("/search", operation_id="get_search", response_model=HitsModel)
async def search(query: FulltextQuery = Depends(FulltextQuery)) -> FulltextHits:
hits: Optional[FulltextHits] = None
+ if query.q is None:
+ raise HTTPException(status_code=400, detail=f"Expected a 'q' query parameter")
try:
hits = process_query(query)
except ValueError as e:
diff --git a/tests/test_web.py b/tests/test_web.py
index 810f8e3..df8b832 100644
--- a/tests/test_web.py
+++ b/tests/test_web.py
@@ -39,6 +39,10 @@ def test_basic_api(client: Any, mocker: Any) -> None:
assert resp.status_code == 200
assert resp.json()
+ # request with no 'q' parameter is an error
+ resp = client.get("/search", headers=headers)
+ assert resp.status_code == 400
+
with open("tests/files/elastic_fulltext_search.json") as f:
elastic_resp = json.loads(f.read())
@@ -49,7 +53,7 @@ def test_basic_api(client: Any, mocker: Any) -> None:
(200, {}, json.dumps(elastic_resp)),
]
- resp = client.get("/search", headers=headers)
+ resp = client.get("/search?q=blood", headers=headers)
assert resp.status_code == 200
assert resp.json()