Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Casper Welzel Andersen <43357585+CasperWA@users.noreply.github.com>
  • Loading branch information
ml-evs and CasperWA committed Jul 2, 2020
1 parent 9b293c9 commit 65e5136
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 31 deletions.
9 changes: 4 additions & 5 deletions openapi/index_openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,10 @@
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
},
"text/csv": {
"schema": {}
"schema": {
"type": "string"
}
}
}
}
Expand Down Expand Up @@ -1606,7 +1605,7 @@
"representation": {
"title": "Representation",
"type": "string",
"description": "A string with the part of the URL following the versioned or unversioned base URL that serves the API.\nQuery parameters that have not been used in processing the request MAY be omitted.\nIn particular, if no query parameters have been involved in processing the request, the query pary of the URL MAY be excluded.\nExample: `/structures?filter=nelements=2`"
"description": "A string with the part of the URL following the versioned or unversioned base URL that serves the API.\nQuery parameters that have not been used in processing the request MAY be omitted.\nIn particular, if no query parameters have been involved in processing the request, the query part of the URL MAY be excluded.\nExample: `/structures?filter=nelements=2`"
}
},
"description": "Information on the query that was requested. "
Expand Down
9 changes: 4 additions & 5 deletions openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -879,11 +879,10 @@
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {}
},
"text/csv": {
"schema": {}
"schema": {
"type": "string"
}
}
}
}
Expand Down Expand Up @@ -2783,7 +2782,7 @@
"representation": {
"title": "Representation",
"type": "string",
"description": "A string with the part of the URL following the versioned or unversioned base URL that serves the API.\nQuery parameters that have not been used in processing the request MAY be omitted.\nIn particular, if no query parameters have been involved in processing the request, the query pary of the URL MAY be excluded.\nExample: `/structures?filter=nelements=2`"
"description": "A string with the part of the URL following the versioned or unversioned base URL that serves the API.\nQuery parameters that have not been used in processing the request MAY be omitted.\nIn particular, if no query parameters have been involved in processing the request, the query part of the URL MAY be excluded.\nExample: `/structures?filter=nelements=2`"
}
},
"description": "Information on the query that was requested. "
Expand Down
2 changes: 1 addition & 1 deletion optimade/models/optimade_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class ResponseMetaQuery(BaseModel):
...,
description="""A string with the part of the URL following the versioned or unversioned base URL that serves the API.
Query parameters that have not been used in processing the request MAY be omitted.
In particular, if no query parameters have been involved in processing the request, the query pary of the URL MAY be excluded.
In particular, if no query parameters have been involved in processing the request, the query part of the URL MAY be excluded.
Example: `/structures?filter=nelements=2`""",
)

Expand Down
2 changes: 1 addition & 1 deletion optimade/server/routers/index_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from optimade.server.config import CONFIG

from .utils import meta_values, get_base_url
from optimade.server.routers.utils import meta_values, get_base_url


router = APIRouter(redirect_slashes=True)
Expand Down
4 changes: 2 additions & 2 deletions optimade/server/routers/landing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from starlette.routing import Router, Route
from optimade import __api_version__

from . import ENTRY_COLLECTIONS
from .utils import meta_values
from optimade.server.routers import ENTRY_COLLECTIONS
from optimade.server.routers.utils import meta_values
from optimade.server.config import CONFIG

template_dir = Path(__file__).parent.joinpath("static").resolve()
Expand Down
17 changes: 6 additions & 11 deletions optimade/server/routers/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@
router = APIRouter(redirect_slashes=True)


class CsvResponse(Response):
media_type = "text/csv"


@router.get(
"/versions",
tags=["Versions"],
responses={
200: {
"description": "Successful Response",
"content": {"text/csv": {"schema": {}}},
}
},
"/versions", tags=["Versions"], response_class=CsvResponse,
)
def get_versions(request: Request):
"""Respond with the text/csv representation for the served versions."""
version = BASE_URL_PREFIXES["major"].replace("/v", "")
response = f"version\n{version}"
return Response(
content=response, media_type="text/csv", headers={"header": "present"}
)
return CsvResponse(content=response, headers={"header": "present"})
8 changes: 2 additions & 6 deletions tests/server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ def get_regular_client() -> TestClient:
from optimade.server.main import app
from optimade.server.routers import info, links, references, structures

# We need to remove the version prefixes in order to have the tests run correctly.
app.include_router(info.router, prefix=VERSION_PREFIX)
app.include_router(links.router, prefix=VERSION_PREFIX)
app.include_router(references.router, prefix=VERSION_PREFIX)
app.include_router(structures.router, prefix=VERSION_PREFIX)
for endpoint in (info, links, references, structures):
app.include_router(endpoint.router, prefix=VERSION_PREFIX)
# need to explicitly set base_url, as the default "http://testserver"
# does not validate as pydantic AnyUrl model
return TestClient(app, base_url=f"http://example.org{VERSION_PREFIX}")
Expand All @@ -31,7 +28,6 @@ def get_index_client() -> TestClient:
from optimade.server.main_index import app
from optimade.server.routers import index_info, links

# # We need to remove the version prefixes in order to have the tests run correctly.
app.include_router(index_info.router, prefix=VERSION_PREFIX)
app.include_router(links.router, prefix=VERSION_PREFIX)
# need to explicitly set base_url, as the default "http://testserver"
Expand Down

0 comments on commit 65e5136

Please sign in to comment.