Skip to content

Commit

Permalink
Fix some tests
Browse files Browse the repository at this point in the history
Make all parts passed as mongo_kwargs to `update_query` clean Python
types.
  • Loading branch information
CasperWA committed Jun 9, 2021
1 parent 4535daf commit c1719df
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion optimade_gateway/queries/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async def update_query(
update_kwargs = {"$set": {"last_modified": update_time}}

if mongo_kwargs:
update_kwargs.update(mongo_kwargs)
update_kwargs.update(await clean_python_types(mongo_kwargs))

if operator and operator == "$set":
update_kwargs["$set"].update({field: await clean_python_types(value)})
Expand Down
5 changes: 3 additions & 2 deletions optimade_gateway/routers/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from optimade_gateway.common.config import CONFIG
from optimade_gateway.mappers import QueryMapper
from optimade_gateway.models import (
GatewayQueryResponse,
QueryCreate,
QueryResource,
QueryState,
Expand Down Expand Up @@ -114,7 +115,7 @@ async def post_queries(

@ROUTER.get(
"/queries/{query_id:path}",
response_model=Union[EntryResponseMany, ErrorResponse],
response_model=Union[EntryResponseMany, ErrorResponse, GatewayQueryResponse],
response_model_exclude_defaults=False,
response_model_exclude_none=False,
response_model_exclude_unset=True,
Expand All @@ -124,7 +125,7 @@ async def get_query(
request: Request,
query_id: str,
response: Response,
) -> Union[EntryResponseMany, ErrorResponse]:
) -> Union[EntryResponseMany, ErrorResponse, GatewayQueryResponse]:
"""`GET /queries/{query_id}`
Return the response from a query
Expand Down
3 changes: 2 additions & 1 deletion tests/routers/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ async def test_get_info(
"redoc",
"search",
"queries",
"databases",
]
)
entry_types_by_format = {"json": ["gateways", "queries"]}
entry_types_by_format = {"json": ["databases", "gateways", "queries"]}

response = await client("/info")

Expand Down
9 changes: 6 additions & 3 deletions tests/routers/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,13 @@ async def test_query_results(
"""Test POST /queries and GET /queries/{id}"""
import asyncio
from optimade.models import EntryResponseMany
from optimade.models import StructureResponseMany

from optimade_gateway.common.config import CONFIG
from optimade_gateway.models.queries import QueryState, QueryResource
from optimade_gateway.models.queries import (
GatewayQueryResponse,
QueryState,
QueryResource,
)

data = {
"id": "test",
Expand Down Expand Up @@ -193,7 +196,7 @@ async def test_query_results(
response = await client(f"/queries/{data['id']}")
assert response.status_code == 200, f"Request failed: {response.json()}"

response = StructureResponseMany(**response.json())
response = GatewayQueryResponse(**response.json())
assert response.data
assert (
getattr(response.meta, f"_{CONFIG.provider.prefix}_query", "NOT FOUND")
Expand Down

0 comments on commit c1719df

Please sign in to comment.