Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
edmondchuc committed Aug 31, 2022
1 parent 3536adb commit 393ecfc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/linkeddata_api/domain/viewer/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from . import json


def _handle_json_response(uri: str, sparql_endpoint: str) -> domain.schema.Resource:
def _handle_json_response(uri: str, sparql_endpoint: str) -> str:
try:
result = json.get(uri, sparql_endpoint)
except (RequestError, SPARQLNotFoundError, SPARQLResultJSONError) as err:
Expand All @@ -33,7 +33,7 @@ def _handle_rdf_response(
graph.parse(data=response.text, format=format_)

if len(graph) == 0:
return "Resource not found", 404
raise SPARQLNotFoundError(f"Resource with URI {uri} not found.")

if not include_incoming_relationships:
graph.remove((None, None, URIRef(uri)))
Expand Down
10 changes: 9 additions & 1 deletion src/linkeddata_api/views/api_v1/viewer/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ def get_resource():
True if include_incoming_relationships == "true" else False
)

if uri is None or sparql_endpoint is None:
err_msg = "Required query parameters 'uri' or 'sparql_endpoint' was not provided."
raise HTTPException(err_msg, Response(err_msg, 404))

logger.info(
"""
GET /viewer/resource
Expand Down Expand Up @@ -65,4 +69,8 @@ def get_resource():
response=Response(str(err), mimetype="text/plain", status=500),
) from err

return Response(result, mimetype=format_)
return Response(
result,
mimetype=format_,
headers={"cache-control": "max-age=600, s-maxage=3600"},
)
22 changes: 11 additions & 11 deletions tests/api_v1/resource/test_resource_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

@pytest.fixture
def url() -> str:
return "/api/v1.0/resource"
return "/api/v1.0/viewer/resource"


value = """
Expand Down Expand Up @@ -56,7 +56,7 @@ def url() -> str:
"text/turtle",
"text/turtle",
"https://linked.data.gov.au/def/nrm",
"dawe_vocabs_core",
"https://graphdb.tern.org.au/repositories/dawe_vocabs_core",
"false",
value,
22,
Expand All @@ -68,10 +68,10 @@ def url() -> str:
"text/turtle",
"text/html",
"https://linked.data.gov.au/def/nrm/not-exist",
"dawe_vocabs_core",
"https://graphdb.tern.org.au/repositories/dawe_vocabs_core",
"false",
"",
22,
None,
),
# RDF4J repository does not exist
(
Expand All @@ -80,10 +80,10 @@ def url() -> str:
"text/turtle",
"text/html",
"https://linked.data.gov.au/def/nrm",
"dawe_vocabs_core-not-exist",
"https://graphdb.tern.org.au/repositories/dawe_vocabs_core-not-exist",
"false",
"",
22,
None,
),
# Include incoming relationships
(
Expand All @@ -92,10 +92,10 @@ def url() -> str:
"text/turtle",
"text/turtle",
"https://linked.data.gov.au/def/nrm",
"dawe_vocabs_core",
"https://graphdb.tern.org.au/repositories/dawe_vocabs_core",
"true",
value,
23,
3179,
),
# No accepted format, default to text/turtle
(
Expand All @@ -104,7 +104,7 @@ def url() -> str:
"",
"text/turtle",
"https://linked.data.gov.au/def/nrm",
"dawe_vocabs_core",
"https://graphdb.tern.org.au/repositories/dawe_vocabs_core",
"false",
value,
22,
Expand Down Expand Up @@ -134,11 +134,11 @@ def test_describe(
response: TestResponse = client.get(
url,
query_string={
"repository_id": repository_id,
"sparql_endpoint": repository_id,
"uri": uri,
"include_incoming_relationships": include_incoming_relationships,
"format": accept_format,
},
headers={"accept": accept_format},
)
assert response.status_code == response_status_code
assert expected_format in response.headers.get("content-type")
Expand Down

0 comments on commit 393ecfc

Please sign in to comment.