From afdf755b91428f858d867858c9d357e1a74e75d7 Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Thu, 17 Sep 2020 13:34:10 +0200 Subject: [PATCH 1/7] Update info in openapi.yaml --- fdp/openapi/openapi.yaml | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/fdp/openapi/openapi.yaml b/fdp/openapi/openapi.yaml index d6a2e5f..0015369 100644 --- a/fdp/openapi/openapi.yaml +++ b/fdp/openapi/openapi.yaml @@ -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: info@esciencecenter.nl 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: / From 46d3f1d55114b47395f4c1211b6148efdc2b34d3 Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Thu, 17 Sep 2020 13:37:54 +0200 Subject: [PATCH 2/7] remove the hostname localhost --- fdp/config.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/fdp/config.py b/fdp/config.py index 0e6a7c5..8c68842 100644 --- a/fdp/config.py +++ b/fdp/config.py @@ -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 From ba8d6323343392a4393ab5ce908c8bce3dc61b7a Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Thu, 17 Sep 2020 15:54:59 +0200 Subject: [PATCH 3/7] Update put method for FDP layer --- fdp/api/metadata.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fdp/api/metadata.py b/fdp/api/metadata.py index 43170bd..394d58d 100644 --- a/fdp/api/metadata.py +++ b/fdp/api/metadata.py @@ -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(): From cb3a8c41729303b22164d50160334adf549e2b82 Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Thu, 17 Sep 2020 15:55:57 +0200 Subject: [PATCH 4/7] refactor targetURI --- fdp/api/metadata.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fdp/api/metadata.py b/fdp/api/metadata.py index 394d58d..dae4c33 100644 --- a/fdp/api/metadata.py +++ b/fdp/api/metadata.py @@ -139,9 +139,10 @@ 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) @@ -149,9 +150,10 @@ 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') From a07d88e6be10bf48c69fdf473df40de7fe51b579 Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Thu, 17 Sep 2020 15:58:01 +0200 Subject: [PATCH 5/7] add tests for put method --- tests/test_endpoints.py | 64 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/tests/test_endpoints.py b/tests/test_endpoints.py index bf550ff..a83a54e 100644 --- a/tests/test_endpoints.py +++ b/tests/test_endpoints.py @@ -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 @@ -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 @@ -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' @@ -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 @@ -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 @@ -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' @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 From 73d77d9b4a897d3c44f64bf93092733b0b4b80df Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Thu, 17 Sep 2020 16:03:02 +0200 Subject: [PATCH 6/7] add ttl files for testing put method --- tests/data/catalog01_update.ttl | 17 +++++++++++++++++ tests/data/dataset01_update.ttl | 17 +++++++++++++++++ tests/data/dist01_update.ttl | 15 +++++++++++++++ tests/data/fdp_update.ttl | 24 ++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 tests/data/catalog01_update.ttl create mode 100644 tests/data/dataset01_update.ttl create mode 100644 tests/data/dist01_update.ttl create mode 100644 tests/data/fdp_update.ttl diff --git a/tests/data/catalog01_update.ttl b/tests/data/catalog01_update.ttl new file mode 100644 index 0000000..a2f5261 --- /dev/null +++ b/tests/data/catalog01_update.ttl @@ -0,0 +1,17 @@ +@prefix schema: . +@prefix xsd: . +@prefix dcat: . +@prefix dcterms: . +@prefix fdp: . +@prefix dbp: . + + a dcat:Catalog ; + dcterms:title "First sample catalog"; + dcterms:hasVersion "2.0" ; + dcterms:publisher ; + dcterms:isPartOf ; + fdp:metadataIdentifier ; + fdp:metadataIssued "2016-10-27T00:00:00"^^xsd:dateTime ; + fdp:metadataModified "2016-10-27T00:00:00"^^xsd:dateTime ; + dcat:dataset ; + dcat:themeTaxonomy dbp:Breeding . diff --git a/tests/data/dataset01_update.ttl b/tests/data/dataset01_update.ttl new file mode 100644 index 0000000..a440f77 --- /dev/null +++ b/tests/data/dataset01_update.ttl @@ -0,0 +1,17 @@ +@prefix schema: . +@prefix xsd: . +@prefix dcat: . +@prefix dcterms: . +@prefix fdp: . +@prefix dbp: . + + a dcat:Dataset ; + dcterms:title "BreeDB tomato passport dataset"^^xsd:string ; + dcterms:publisher ; + dcterms:hasVersion "2.0"^^xsd:string ; + dcterms:isPartOf ; + fdp:metadataIdentifier ; + fdp:metadataIssued "2016-10-27T09:30:00"^^xsd:dateTime ; + fdp:metadataModified "2016-10-27T09:30:00"^^xsd:dateTime ; + dcat:distribution ; + dcat:theme dbp:Plant_breeding . diff --git a/tests/data/dist01_update.ttl b/tests/data/dist01_update.ttl new file mode 100644 index 0000000..a492436 --- /dev/null +++ b/tests/data/dist01_update.ttl @@ -0,0 +1,15 @@ +@prefix xsd: . +@prefix dcat: . +@prefix dcterms: . +@prefix fdp: . + + a dcat:Distribution ; + dcterms:title "SPARQL endpoint for BreeDB tomato passport data"^^xsd:string ; + dcterms:license ; + dcterms:hasVersion "2.0"^^xsd:string ; + dcterms:isPartOf ; + fdp:metadataIdentifier ; + 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 . diff --git a/tests/data/fdp_update.ttl b/tests/data/fdp_update.ttl new file mode 100644 index 0000000..be3a8ab --- /dev/null +++ b/tests/data/fdp_update.ttl @@ -0,0 +1,24 @@ +@prefix ex: . +@prefix fdp: . +@prefix dcterms: . +@prefix lang: . +@prefix rdfs: . +@prefix xsd: . +@prefix r3d: . + + 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 ; + dcterms:language lang:en ; + dcterms:conformsTo ; + 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 + , + ; + r3d:repositoryIdentifier ex:fdp_repositoryID . From 0dbae4c8defaef31976960f2af459f7447ac9fa6 Mon Sep 17 00:00:00 2001 From: Cunliang Geng Date: Thu, 17 Sep 2020 16:03:14 +0200 Subject: [PATCH 7/7] remove data from gitignore --- .gitignore | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 53de875..5f4819e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,4 @@ playground .vscode # Mac -.DS_Store - -data \ No newline at end of file +.DS_Store \ No newline at end of file