Skip to content

Commit

Permalink
Merge pull request #27 from ternaustralia/edmond/sparql-describe
Browse files Browse the repository at this point in the history
Add resource describe default format as text/turtle
  • Loading branch information
edmondchuc authored Jul 5, 2022
2 parents b70e8b3 + 9b3214f commit c206047
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/linkeddata_api/views/api_v1/resource/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def get_resource():
repository_id = request.args.get("repository_id")
uri = request.args.get("uri")
format_ = request.headers.get("accept")
if not format_:
format_ = "text/turtle"
include_incoming_relationships = request.args.get("include_incoming_relationships")
include_incoming_relationships = (
True if include_incoming_relationships == "true" else False
Expand All @@ -38,7 +40,7 @@ def get_resource():

graph = rdf.create_graph()
graph.parse(data=response.text)
print(len(graph))

if len(graph) == 0:
return "Resource not found", 404

Expand Down
18 changes: 17 additions & 1 deletion tests/api_v1/resource/test_resource_describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def url() -> str:
@pytest.mark.parametrize(
"mocked_status_code, response_status_code, accept_format, expected_format, uri, repository_id, include_incoming_relationships, content, expected_triples_count",
[
# Expected usage
(
200,
200,
Expand All @@ -60,6 +61,7 @@ def url() -> str:
value,
22,
),
# URI resource does not exist
(
200,
404,
Expand All @@ -71,6 +73,7 @@ def url() -> str:
"",
22,
),
# RDF4J repository does not exist
(
415,
502,
Expand All @@ -82,6 +85,7 @@ def url() -> str:
"",
22,
),
# Include incoming relationships
(
200,
200,
Expand All @@ -93,6 +97,18 @@ def url() -> str:
value,
23,
),
# No accepted format, default to text/turtle
(
200,
200,
"",
"text/turtle",
"https://linked.data.gov.au/def/nrm",
"dawe_vocabs_core",
"false",
value,
22,
),
],
)
def test_describe(
Expand Down Expand Up @@ -129,5 +145,5 @@ def test_describe(

if response.status_code == 200:
graph = Graph()
graph.parse(data=response.text, format=accept_format)
graph.parse(data=response.text, format=expected_format)
assert len(graph) == expected_triples_count

0 comments on commit c206047

Please sign in to comment.