Skip to content

Commit

Permalink
Bugfix/810 concept id as uri (#811)
Browse files Browse the repository at this point in the history
* Add testfile to import with non-numeric ids. Refs #810

* Fix routing of concept_id with slashes. Add tests for rdf downloads. Refs #810
  • Loading branch information
koenedaele committed Mar 22, 2023
1 parent 50e24b9 commit b3d279f
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 12 deletions.
22 changes: 11 additions & 11 deletions atramhasis/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ def includeme(config):
config.add_route('atramhasis.rdf_full_export_turtle_ext', pattern='/conceptschemes/{scheme_id}/c.ttl')
config.add_route('atramhasis.rdf_conceptscheme_export_ext', pattern='/conceptschemes/{scheme_id}.rdf')
config.add_route('atramhasis.rdf_conceptscheme_export_turtle_ext', pattern='/conceptschemes/{scheme_id}.ttl')
config.add_route('atramhasis.rdf_individual_export_ext', pattern='/conceptschemes/{scheme_id}/c/{c_id}.rdf')
config.add_route('atramhasis.rdf_individual_export_turtle_ext', pattern='/conceptschemes/{scheme_id}/c/{c_id}.ttl')
config.add_route('atramhasis.rdf_individual_export_ext', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}.rdf')
config.add_route('atramhasis.rdf_individual_export_turtle_ext', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}.ttl')
config.add_route('atramhasis.rdf_conceptscheme_jsonld_ext', pattern='/conceptschemes/{scheme_id}.jsonld')
config.add_route('atramhasis.rdf_individual_jsonld_ext', pattern='/conceptschemes/{scheme_id}/c/{c_id}.jsonld')
config.add_route('atramhasis.rdf_individual_jsonld_ext', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}.jsonld')

config.add_route('conceptschemes', pattern='/conceptschemes', accept='text/html', request_method="GET")
config.add_route('conceptscheme', pattern='/conceptschemes/{scheme_id}', accept='text/html', request_method="GET")
config.add_route('concept', pattern='/conceptschemes/{scheme_id}/c/{c_id}', accept='text/html',
config.add_route('concept', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}', accept='text/html',
request_method="GET")
config.add_route('search_result', pattern='/conceptschemes/{scheme_id}/c', accept='text/html')
config.add_route('scheme_root', pattern='/conceptschemes/{scheme_id}/c/', accept='text/html')
Expand All @@ -51,13 +51,13 @@ def includeme(config):
accept='application/json', request_method='PUT')
config.add_route('atramhasis.get_conceptscheme', pattern='/conceptschemes/{scheme_id}', accept='application/json')
config.add_route('atramhasis.get_conceptschemes', pattern='/conceptschemes', accept='application/json')
config.add_route('atramhasis.get_concept', pattern='/conceptschemes/{scheme_id}/c/{c_id}',
config.add_route('atramhasis.get_concept', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/json', request_method="GET")
config.add_route('atramhasis.add_concept', pattern='/conceptschemes/{scheme_id}/c', accept='application/json',
request_method="POST")
config.add_route('atramhasis.edit_concept', pattern='/conceptschemes/{scheme_id}/c/{c_id}',
config.add_route('atramhasis.edit_concept', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/json', request_method="PUT")
config.add_route('atramhasis.delete_concept', pattern='/conceptschemes/{scheme_id}/c/{c_id}',
config.add_route('atramhasis.delete_concept', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/json', request_method="DELETE")
config.add_route('atramhasis.list_languages', pattern='/languages', accept='application/json',
request_method="GET")
Expand Down Expand Up @@ -86,15 +86,15 @@ def includeme(config):
accept='text/turtle')
config.add_route('atramhasis.rdf_conceptscheme_export_turtle_x', pattern='/conceptschemes/{scheme_id}',
accept='application/x-turtle')
config.add_route('atramhasis.rdf_individual_export', pattern='/conceptschemes/{scheme_id}/c/{c_id}',
config.add_route('atramhasis.rdf_individual_export', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/rdf+xml')
config.add_route('atramhasis.rdf_individual_export_turtle', pattern='/conceptschemes/{scheme_id}/c/{c_id}',
config.add_route('atramhasis.rdf_individual_export_turtle', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='text/turtle')
config.add_route('atramhasis.rdf_individual_export_turtle_x', pattern='/conceptschemes/{scheme_id}/c/{c_id}',
config.add_route('atramhasis.rdf_individual_export_turtle_x', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/x-turtle')
config.add_route('atramhasis.rdf_conceptscheme_jsonld', pattern='/conceptschemes/{scheme_id}',
accept='application/ld+json')
config.add_route('atramhasis.rdf_individual_jsonld', pattern='/conceptschemes/{scheme_id}/c/{c_id}',
config.add_route('atramhasis.rdf_individual_jsonld', pattern='/conceptschemes/{scheme_id}/c/{c_id:.*}',
accept='application/ld+json')
config.add_route('atramhasis.providers', pattern='/providers')
config.add_route('atramhasis.provider', pattern='/providers/{id}')
2 changes: 1 addition & 1 deletion atramhasis/views/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, request):
raise ConceptSchemeNotFoundException(self.scheme_id) # pragma: no cover
if 'c_id' in self.request.matchdict.keys():
self.c_id = self.request.matchdict['c_id']
if not self.c_id.isdigit() or not self.provider.get_by_id(int(self.c_id)):
if not self.provider.get_by_id(self.c_id):
raise ConceptNotFoundException(self.c_id)

@audit
Expand Down
7 changes: 7 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ def fill_db():
'labels': [
{'type': 'prefLabel', 'language': 'nl', 'label': 'label'}
],
},
{
'id': 'http://id.manual.org/manual/68',
'uri': 'http://id.manual.org/manual/68',
'labels': [
{'type': 'prefLabel', 'language': 'nl', 'label': 'handmatig'}
],
}]
),
ConceptScheme(id=10, uri='urn:x-vioe:manual'),
Expand Down
47 changes: 47 additions & 0 deletions tests/data/bluebirds.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@prefix dcterms: <http://purl.org/dc/terms/> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

<http://id.bluebirds.org/bird> a skos:Concept ;
skos:inScheme <http://id.bluebirds.org> ;
skos:narrower <http://id.bluebirds.org/parrot> ;
skos:narrower <http://id.bluebirds.org/579A439C-1A7A-476A-92C3-8A74ABD6B3DB> ;
skos:prefLabel "Bird"@en,
"Vogel"@nl .

<http://id.bluebirds.org/parrot> a skos:Concept ;
dcterms:identifier "parrot" ;
skos:inScheme <http://id.bluebirds.org> ;
skos:narrower <http://id.bluebirds.org/norwegianblue> ;
skos:prefLabel "Parrot"@en,
"Papegaai"@nl .

<http://id.bluebirds.org/norwegianblue> a skos:Concept ;
dcterms:identifier "norwegianblue" ;
skos:inScheme <http://id.bluebirds.org> ;
skos:broader <http://id.bluebirds.org/parrot> ;
skos:relatedMatch <http://id.slugs.org/slug> ;
skos:prefLabel "Norwegian Blue"@en,
"Noorse Blauwe"@nl .

<http://id.bluebirds.org/579A439C-1A7A-476A-92C3-8A74ABD6B3DB> a skos:Concept ;
dcterms:identifier "579A439C-1A7A-476A-92C3-8A74ABD6B3DB" ;
skos:inScheme <http://id.bluebirds.org> ;
skos:narrower <http://id.bluebirds.org/blauwereiger> ;
skos:prefLabel "Heron"@en,
"Héron"@fr,
"Reiger"@nl .

<http://id.bluebirds.org/blauwereiger> a skos:Concept ;
dcterms:identifier "blauwereiger" ;
skos:inScheme <http://id.bluebirds.org> ;
skos:prefLabel "Grey heron"@en,
"Héron cendré"@fr,
"Blauwe reiger"@nl,
"Ardea cinerea"@la .

<http://id.bluebirds.org> a skos:ConceptScheme ;
dcterms:identifier "BLUEBIRDS" ;
skos:hasTopConcept <http://id.bluebirds.org/bird> ;
skos:prefLabel "Blue birds"@en,
"Blauwe vogels"@nl .
20 changes: 20 additions & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,26 @@ def test_rdf_individual_turtle_ext(self):
self.assertEqual('200 OK', ttl_response.status)
self.assertEqual('text/turtle', ttl_response.content_type)

def test_rdf_individual_jsonld_ext_manual(self):
res = self.testapp.get('/conceptschemes/manual-ids/c/manual-1.jsonld')
self.assertEqual('200 OK', res.status)
self.assertEqual('application/ld+json', res.content_type)

def test_rdf_individual_xml_ext_manual(self):
rdf_response = self.testapp.get('/conceptschemes/manual-ids/c/manual-2.rdf')
self.assertEqual('200 OK', rdf_response.status)
self.assertEqual('application/rdf+xml', rdf_response.content_type)

def test_rdf_individual_turtle_manual(self):
ttl_response = self.testapp.get('/conceptschemes/manual-ids/c/manual-1.ttl')
self.assertEqual('200 OK', ttl_response.status)
self.assertEqual('text/turtle', ttl_response.content_type)

def test_rdf_individual_turtle_manual_uri(self):
ttl_response = self.testapp.get('/conceptschemes/manual-ids/c/http://id.manual.org/manual/68.ttl')
self.assertEqual('200 OK', ttl_response.status)
self.assertEqual('text/turtle', ttl_response.content_type)

def test_rdf_individual_not_found(self):
res = self.testapp.get('/conceptschemes/TREES/c/test.ttl', headers={'Accept': 'text/turtle'}, status=404,
expect_errors=True)
Expand Down
21 changes: 21 additions & 0 deletions tests/test_import_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

test_data_rdf = os.path.join(TEST_DIR, 'data', 'trees.rdf')
test_data_ttl = os.path.join(TEST_DIR, 'data', 'trees.ttl')
test_data_ttl_string_id = os.path.join(TEST_DIR, 'data', 'bluebirds.ttl')
test_data_json = os.path.join(TEST_DIR, 'data', 'trees.json')
test_data_csv = os.path.join(TEST_DIR, 'data', 'menu.csv')

Expand Down Expand Up @@ -84,6 +85,21 @@ def _check_menu(self, uri_pattern=None):
self.assertIn('Mornay', eb.notes[0].note)
self.assertEqual('note', eb.notes[0].type)

def _check_parrots(self, conceptscheme_label):
sql_prov = SQLAlchemyProvider({'id': 'PARROTS', 'conceptscheme_id': 1}, self.session)

bird = sql_prov.get_by_id('http://id.parrots.org/bird')
assert sql_prov.get_by_uri('http://id.parrots.org/bird') == \
sql_prov.get_by_id('http://id.parrots.org/bird')
parrot = sql_prov.get_by_id('parrot')
assert parrot
assert not sql_prov.get_by_id('bird')
blue = sql_prov.get_by_id('norwegianblue')
assert blue in parrot.narrower
reiger = sql_prov.get_by_id('579A439C-1A7A-476A-92C3-8A74ABD6B3DB')
blauwereiger = sql_prov.get_by_id('blauwereiger')
assert blauwereiger in reiger.narrower

def test_import_rdf(self):
sys.argv = ['import_file', '--from', test_data_rdf, '--to', SETTINGS['sqlalchemy.url']]
import_file.main(sys.argv)
Expand All @@ -96,6 +112,11 @@ def test_import_ttl(self):
tests.db_filled = True
self._check_trees('Different types of trees')

def test_import_ttl_string_id(self):
sys.argv = ['import_file', '--from', test_data_ttl_string_id, '--to', SETTINGS['sqlalchemy.url']]
import_file.main(sys.argv)
tests.db_filled = True

def test_import_json(self):
sys.argv = ['import_file', '--from', test_data_json,
'--to', SETTINGS['sqlalchemy.url'],
Expand Down

0 comments on commit b3d279f

Please sign in to comment.