Skip to content

Commit

Permalink
#624 make jsonld links work (#630)
Browse files Browse the repository at this point in the history
Co-authored-by: Emrys <roefemr@cronos.be>
  • Loading branch information
roefem and Emrys committed Oct 21, 2020
1 parent ca58c9f commit 2b30990
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions atramhasis/audit.py
Expand Up @@ -16,6 +16,8 @@ def _origin_from_request(request):
return 'HTML'
elif 'application/json' in request.accept:
return 'REST'
elif 'application/ld+json' in request.accept:
return 'RDF'
else:
return None

Expand Down
6 changes: 6 additions & 0 deletions atramhasis/routes.py
Expand Up @@ -27,6 +27,8 @@ def includeme(config):
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_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('conceptschemes', pattern='/conceptschemes', accept='text/html', request_method="GET")
config.add_route('conceptscheme', pattern='/conceptschemes/{scheme_id}', accept='text/html', request_method="GET")
Expand Down Expand Up @@ -83,3 +85,7 @@ def includeme(config):
accept='text/turtle')
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}',
accept='application/ld+json')
13 changes: 13 additions & 0 deletions atramhasis/views/rdf.py
Expand Up @@ -4,6 +4,7 @@

from pyramid.response import Response, FileResponse
from pyramid.view import view_defaults, view_config
from pyramid_skosprovider.views import ProviderView
from skosprovider_rdf import utils

from atramhasis.errors import (
Expand Down Expand Up @@ -119,3 +120,15 @@ def rdf_individual_export_turtle(self):
response.body = graph.serialize(format='turtle')
response.content_disposition = 'attachment; filename="%s.ttl"' % (str(self.c_id),)
return response

@audit
@view_config(route_name='atramhasis.rdf_conceptscheme_jsonld', permission='view', renderer='skosjsonld')
@view_config(route_name='atramhasis.rdf_conceptscheme_jsonld_ext', permission='view', renderer='skosjsonld')
def get_conceptscheme_jsonld(self):
return ProviderView(self.request).get_conceptscheme_jsonld()

@audit
@view_config(route_name='atramhasis.rdf_individual_jsonld', permission='view', renderer='skosjsonld')
@view_config(route_name='atramhasis.rdf_individual_jsonld_ext', permission='view', renderer='skosjsonld')
def get_concept(self):
return ProviderView(self.request).get_concept()
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -7,8 +7,8 @@ skosprovider==0.7.1
#-e git+https://github.com/koenedaele/skosprovider.git@develop#egg=skosprovider
skosprovider_sqlalchemy==0.6.0
#-e git+https://github.com/koenedaele/skosprovider_sqlalchemy.git@0.6.0#egg=skosprovider_sqlalchemy
pyramid_skosprovider==0.9.0
#-e git+https://github.com/koenedaele/pyramid_skosprovider.git@0.9.0#egg=pyramid_skosprovider
pyramid_skosprovider==0.9.1
#-e git+https://github.com/koenedaele/pyramid_skosprovider.git@0.9.1#egg=pyramid_skosprovider
skosprovider_rdf==0.8.1
#-e git+https://github.com/OnroerendErfgoed/skosprovider_rdf.git@develop#egg=skosprovider_rdf
skosprovider_getty==0.5.1
Expand Down
20 changes: 20 additions & 0 deletions tests/test_functional.py
Expand Up @@ -723,6 +723,26 @@ def test_rdf_conceptscheme_turtle_ext(self):
self.assertEqual('200 OK', ttl_response.status)
self.assertEqual('text/turtle', ttl_response.content_type)

def test_rdf_conceptscheme_jsonld(self):
res = self.testapp.get('/conceptschemes/MATERIALS', headers={'Accept': 'application/ld+json'})
self.assertEqual('200 OK', res.status)
self.assertEqual('application/ld+json', res.content_type)

def test_rdf_conceptscheme_jsonld_ext(self):
res = self.testapp.get('/conceptschemes/MATERIALS.jsonld')
self.assertEqual('200 OK', res.status)
self.assertEqual('application/ld+json', res.content_type)

def test_rdf_individual_jsonld(self):
res = self.testapp.get('/conceptschemes/MATERIALS/c/1', headers={'Accept': 'application/ld+json'})
self.assertEqual('200 OK', res.status)
self.assertEqual('application/ld+json', res.content_type)

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

def test_rdf_individual_xml(self):
rdf_response = self.testapp.get('/conceptschemes/MATERIALS/c/1', headers={'Accept': 'application/rdf+xml'})
self.assertEqual('200 OK', rdf_response.status)
Expand Down

0 comments on commit 2b30990

Please sign in to comment.