Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #60 from NLeSC/refine4cloud
Browse files Browse the repository at this point in the history
Refine4cloud
  • Loading branch information
CunliangGeng authored Sep 25, 2020
2 parents 4e94ea1 + 0dbae4c commit 02b5ea6
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 18 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,4 @@ playground
.vscode

# Mac
.DS_Store

data
.DS_Store
16 changes: 11 additions & 5 deletions fdp/api/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ def put():
'''
Update FDP metadata
'''
return make_response({'message': 'Method Not Allowed'}, 405)
targetURI = fairgraph.buildURI('FDP')
if not fairgraph.URIexists(targetURI):
return make_response({'message': 'Not Found'}, 404)
fairgraph.deleteURI(targetURI)
return httpResponsePost('FDP')

class Metadata():

Expand Down Expand Up @@ -135,19 +139,21 @@ def put(self, id):
'''
Update Catalog metadata
'''
if not fairgraph.URIexists(fairgraph.buildURI(self.layer, id)):
targetURI = fairgraph.buildURI(self.layer, id)
if not fairgraph.URIexists(targetURI):
return make_response({'message': 'Not Found'}, 404)
fairgraph.deleteURI(fairgraph.buildURI(self.layer, id))
fairgraph.deleteURI(targetURI)
#TODO validate the id of the request body
return httpResponsePost(self.layer)

def delete(self, id):
'''
Delete the catalog ID and metadata
'''
if not fairgraph.URIexists(fairgraph.buildURI(self.layer, id)):
targetURI = fairgraph.buildURI(self.layer, id)
if not fairgraph.URIexists(targetURI):
return make_response({'message': 'Not Found'}, 404)
fairgraph.deleteURI(fairgraph.buildURI(self.layer, id))
fairgraph.deleteURI(targetURI)
return make_response('', 204)

Catalog = Metadata('Catalog')
Expand Down
4 changes: 1 addition & 3 deletions fdp/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
from fdp.fairgraph import FAIRGraph

def build_base_uri(host, port):
if host == 'localhost':
host = 'http://127.0.0.1'
elif not host.startswith('http'):
if not host.startswith('http'):
host = f'http://{host}'
if int(port) == 80:
base_uri = host
Expand Down
15 changes: 12 additions & 3 deletions fdp/openapi/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
openapi: 3.0.0
info:
description:
Find more about [FAIR Data Point](https://github.com/NLeSC/fairdatapoint).
title: FAIR Data Point
version: "1.0.0"
title: FAIR Data Point REST APIs
description: FAIR Data Point is a RESTful web service that enables data owners
to describe and to expose their datasets (metadata) as well as data users
to discover more information about available datasets according to the
[FAIR Data Principles](https://www.force11.org/group/fairgroup/fairprinciples).
contact:
name: Netherlands eScience Center
url: https://www.esciencecenter.nl/
email: [email protected]
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
externalDocs:
description: Find out more about FAIR Data Point
url: https://github.com/NLeSC/fairdatapoint
servers:
- description: API version 1
url: /
Expand Down
17 changes: 17 additions & 0 deletions tests/data/catalog01_update.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix fdp: <http://rdf.biosemantics.org/ontologies/fdp-o#> .
@prefix dbp: <http://dbpedia.org/resource/> .

<http://0.0.0.0/catalog/catalog01> a dcat:Catalog ;
dcterms:title "First sample catalog";
dcterms:hasVersion "2.0" ;
dcterms:publisher <http://orcid.org/0000-0002-4368-8058> ;
dcterms:isPartOf <http://0.0.0.0/fdp> ;
fdp:metadataIdentifier <http://example.org/catalog01> ;
fdp:metadataIssued "2016-10-27T00:00:00"^^xsd:dateTime ;
fdp:metadataModified "2016-10-27T00:00:00"^^xsd:dateTime ;
dcat:dataset <dataset/breedb> ;
dcat:themeTaxonomy dbp:Breeding .
17 changes: 17 additions & 0 deletions tests/data/dataset01_update.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix fdp: <http://rdf.biosemantics.org/ontologies/fdp-o#> .
@prefix dbp: <http://dbpedia.org/resource/> .

<http://0.0.0.0/dataset/breedb> a dcat:Dataset ;
dcterms:title "BreeDB tomato passport dataset"^^xsd:string ;
dcterms:publisher <http://orcid.org/0000-0002-4368-8058> ;
dcterms:hasVersion "2.0"^^xsd:string ;
dcterms:isPartOf <http://0.0.0.0/catalog/catalog01> ;
fdp:metadataIdentifier <http://example.org/dataset01> ;
fdp:metadataIssued "2016-10-27T09:30:00"^^xsd:dateTime ;
fdp:metadataModified "2016-10-27T09:30:00"^^xsd:dateTime ;
dcat:distribution <http://0.0.0.0/distribution/breedb-sparql> ;
dcat:theme dbp:Plant_breeding .
15 changes: 15 additions & 0 deletions tests/data/dist01_update.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix dcat: <http://www.w3.org/ns/dcat#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix fdp: <http://rdf.biosemantics.org/ontologies/fdp-o#> .

<http://0.0.0.0/distribution/breedb-sparql> a dcat:Distribution ;
dcterms:title "SPARQL endpoint for BreeDB tomato passport data"^^xsd:string ;
dcterms:license <http://rdflicense.appspot.com/rdflicense/cc-by-nc-nd3.0> ;
dcterms:hasVersion "2.0"^^xsd:string ;
dcterms:isPartOf <http://0.0.0.0/dataset/breedb> ;
fdp:metadataIdentifier <http://example.org/dist_breedb-sparql> ;
fdp:metadataIssued "2016-10-27T09:30:00"^^xsd:dateTime ;
fdp:metadataModified "2016-10-27T09:30:00"^^xsd:dateTime ;
dcat:mediaType "application/n-triples"^^xsd:string ;
dcat:accessURL <http://virtuoso.biotools.nl:8888/sparql> .
24 changes: 24 additions & 0 deletions tests/data/fdp_update.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@prefix ex: <http://example.com/ns#> .
@prefix fdp: <http://rdf.biosemantics.org/ontologies/fdp-o#> .
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix lang: <http://id.loc.gov/vocabulary/iso639-1/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix r3d: <http://www.re3data.org/schema/3-0#> .

<http://0.0.0.0/fdp> a r3d:Repository;
dcterms:title "FAIR Data Point service of Plant Breeding group at Wageningen University and Research.";
dcterms:title "FAIR Data Point service van Plant Breeding group van Wageningen University and Research."@nl;
dcterms:hasVersion "0.2";
dcterms:description "This service provides machine-readable descriptions about available datasets (metadata).";
dcterms:publisher <http://orcid.org/0000-0003-1711-7961> ;
dcterms:language lang:en ;
dcterms:conformsTo <https://github.com/FAIRDataTeam/FAIRDataPoint-Spec> ;
fdp:metadataIdentifier ex:fdp;
fdp:metadataIssued "2019-04-09T10:01:00"^^xsd:dateTime;
fdp:metadataModified "2019-05-10T09:00:00"^^xsd:dateTime;
rdfs:label "FAIR Data Point service of Plant Breeding group at Wageningen University and Research.";
r3d:dataCatalog
<http://0.0.0.0/catalog/catalog01>,
<http://0.0.0.0/catalog/catalog02>;
r3d:repositoryIdentifier ex:fdp_repositoryID .
64 changes: 60 additions & 4 deletions tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TestBaseEndpointTests:

# datadir fixture provided via pytest-datadir-ng
def test_fdp(self, client, datadir):
"""Testing post and get to fdp"""
"""Testing post, get and put to fdp"""
rv = client.post('/fdp', data=datadir['fdp.ttl'])
assert rv.status_code == 200
assert 'message' in rv.json
Expand All @@ -38,6 +38,15 @@ def test_fdp(self, client, datadir):
assert b'hasVersion "0.1"' in rv.data
assert b'metadataIssued "2019-04-09T10:01:00"^^xsd:dateTime' in rv.data

rv = client.put('/fdp', data=datadir['fdp_update.ttl'])
assert rv.status_code == 200
assert 'message' in rv.json
assert rv.json['message'] == 'Ok'

rv = client.get('/fdp')
assert rv.status_code == 200
assert b'hasVersion "0.2"' in rv.data

rv = client.delete('/fdp')
assert rv.status_code == 405

Expand Down Expand Up @@ -80,7 +89,7 @@ def test_fdp_invalid(self, client, datadir):
assert 'Not allowed RDF type for layer FDP' in rv.json['message']

def test_catalog(self, client, datadir):
"""Testing post and get to catalog"""
"""Testing post, get, put and delete to catalog"""
rv = client.post('/catalog', data=datadir['catalog01.ttl'])
assert rv.status_code == 200
assert rv.json['message'] == 'Ok'
Expand All @@ -102,6 +111,18 @@ def test_catalog(self, client, datadir):
assert 'GET' in rv.headers['Allow']
assert rv.mimetype == 'text/turtle'
assert b'catalog01' in rv.data
assert b'hasVersion "1.0"' in rv.data

rv = client.put('/catalog/catalog01', data=datadir['catalog01_update.ttl'])
# assert rv.status_code == 200
# assert rv.json['message'] == 'Ok'
print(rv.data)
assert rv.json['message'] == 'Ok'

rv = client.get('/catalog/catalog01')
assert rv.status_code == 200
assert b'catalog01' in rv.data
assert b'hasVersion "2.0"' in rv.data

rv = client.delete('/catalog/catalog01')
assert rv.status_code == 204
Expand All @@ -111,6 +132,11 @@ def test_catalog(self, client, datadir):
assert 'message' in rv.json
assert rv.json['message'] == 'Not Found'

rv = client.put('/catalog/catalog01', data=datadir['catalog01_update.ttl'])
assert rv.status_code == 404
assert 'message' in rv.json
assert rv.json['message'] == 'Not Found'

rv = client.delete('/catalog/catalog01')
assert rv.status_code == 404
assert 'message' in rv.json
Expand All @@ -134,7 +160,7 @@ def test_catalog_invalid(self, client, datadir):
assert 'Validation Report\nConforms: False\nResults (9)' in rv.json['message']

def test_dataset(self, client, datadir):
"""Testing post and get to dataset"""
"""Testing post, get, put and delete to dataset"""
rv = client.post('/dataset', data=datadir['dataset01.ttl'])
assert rv.status_code == 200
assert rv.json['message'] == 'Ok'
Expand All @@ -155,6 +181,16 @@ def test_dataset(self, client, datadir):
assert 'GET' in rv.headers['Allow']
assert rv.mimetype == 'text/turtle'
assert b'breedb' in rv.data
assert b'hasVersion "1.0"' in rv.data

rv = client.put('/dataset/breedb', data=datadir['dataset01_update.ttl'])
assert rv.status_code == 200
assert rv.json['message'] == 'Ok'

rv = client.get('/dataset/breedb', )
assert rv.status_code == 200
assert b'breedb' in rv.data
assert b'hasVersion "2.0"' in rv.data

rv = client.delete('/dataset/breedb')
assert rv.status_code == 204
Expand All @@ -164,6 +200,11 @@ def test_dataset(self, client, datadir):
assert 'message' in rv.json
assert rv.json['message'] == 'Not Found'

rv = client.put('/dataset/breedb', data=datadir['dataset01_update.ttl'])
assert rv.status_code == 404
assert 'message' in rv.json
assert rv.json['message'] == 'Not Found'

rv = client.delete('/dataset/breedb')
assert rv.status_code == 404
assert 'message' in rv.json
Expand All @@ -187,7 +228,7 @@ def test_dataset_invalid(self, client, datadir):
assert 'Validation Report\nConforms: False\nResults (9)' in rv.json['message']

def test_distribution(self, client, datadir):
"""Testing post and get to distribution"""
"""Testing post, get, put and delete to distribution"""

rv = client.post('/distribution', data=datadir['dist01.ttl'])
assert rv.status_code == 200
Expand All @@ -209,6 +250,16 @@ def test_distribution(self, client, datadir):
assert 'GET' in rv.headers['Allow']
assert rv.mimetype == 'text/turtle'
assert b'breedb-sparql' in rv.data
assert b'hasVersion "1.0"' in rv.data

rv = client.put('/distribution/breedb-sparql', data=datadir['dist01_update.ttl'])
assert rv.status_code == 200
assert rv.json['message'] == 'Ok'

rv = client.get('/distribution/breedb-sparql')
assert rv.status_code == 200
assert b'breedb-sparql' in rv.data
assert b'hasVersion "2.0"' in rv.data

rv = client.delete('/distribution/breedb-sparql')
assert rv.status_code == 204
Expand All @@ -218,6 +269,11 @@ def test_distribution(self, client, datadir):
assert 'message' in rv.json
assert rv.json['message'] == 'Not Found'

rv = client.put('/distribution/breedb-sparql', data=datadir['dist01_update.ttl'])
assert rv.status_code == 404
assert 'message' in rv.json
assert rv.json['message'] == 'Not Found'

rv = client.get('/distribution')
assert rv.status_code == 200
assert b'breedb-sparql' not in rv.data
Expand Down

0 comments on commit 02b5ea6

Please sign in to comment.