Skip to content

Commit

Permalink
Rework URI searching. Refs #19
Browse files Browse the repository at this point in the history
  • Loading branch information
koenedaele committed Sep 10, 2015
1 parent 93f7f1f commit 9fcf794
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 8 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- Add the markup attribute to Note json representations. This is a new addition
to skosprovider 0.6.0 that allows marking that a note contains some markup
(currently only HTML).
- Looking for a certain URI is now done with a query parameter in stead of in
the path of a resource. So, `/uris/urn:x-skosprovider:trees` should now be
called as `/uris?uri=urn:x-skosprovider:trees`. The old way is deprecated. It
will still function under version `0.7.0`, but will be removed in a future
version. (#19)

0.6.0 (2015-03-02)
------------------
Expand Down
8 changes: 5 additions & 3 deletions docs/services.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ easily inside a AJAX webbrowser call or by an external program.

The following API can be used by clients:

.. http:get:: /uris/{uri}
.. http:get:: /uris
:synopsis: Look up where a certain URI can be found.

Find more information on a certain :term:`URI`. This can map to eiter
Expand All @@ -21,7 +21,7 @@ The following API can be used by clients:

.. sourcecode:: http

GET /uris/urn:x-skosprovider:trees HTTP/1.1
GET /uris?uri=urn:x-skosprovider:trees HTTP/1.1
Host: localhost:6543
Accept: application/json

Expand All @@ -42,7 +42,7 @@ The following API can be used by clients:

.. sourcecode:: http

GET /uris/http://python.com/trees/larch HTTP/1.1
GET /uris/?uri=http://python.com/trees/larch HTTP/1.1
Host: localhost:6543
Accept: application/json

Expand All @@ -63,6 +63,8 @@ The following API can be used by clients:
}
}

:query uri: The URI to search for.

:statuscode 200: The URI maps to something known by pyramid_skosprovider,
either a conceptscheme, a concept or collection.
:statuscode 404: The URI can't be found by pyramid_skosprovider.
Expand Down
6 changes: 5 additions & 1 deletion pyramid_skosprovider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ def includeme(config):
config.add_request_method(get_skos_registry, 'skos_registry', reify=True)

config.add_route(
'skosprovider.uri',
'skosprovider.uri.deprecated',
'/uris/{uri:.*}'
)
config.add_route(
'skosprovider.uri',
'/uris'
)
config.add_route(
'skosprovider.cs',
'/c'
Expand Down
11 changes: 9 additions & 2 deletions pyramid_skosprovider/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
from pyramid.compat import ascii_native_

from pyramid.httpexceptions import (
HTTPNotFound
HTTPNotFound,
HTTPBadRequest
)

from pyramid_skosprovider.utils import (
Expand All @@ -35,8 +36,14 @@ class ProviderView(RestView):
'''

@view_config(route_name='skosprovider.uri', request_method='GET')
@view_config(route_name='skosprovider.uri.deprecated', request_method='GET')
def get_uri(self):
uri = self.request.matchdict['uri']
uri = self.request.params.get('uri')
if not uri:
if 'uri' in self.request.matchdict:
uri = self.request.matchdict['uri']
else:
return HTTPBadRequest()
provider = self.skos_registry.get_provider(uri)
if provider:
return {
Expand Down
26 changes: 24 additions & 2 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class RestFunctionalTests(FunctionalTests):

def test_get_uri_cs_json(self):
res = self.testapp.get(
'/uris/http://python.com/trees',
'/uris?uri=http://python.com/trees',
{},
{ascii_native_('Accept'): ascii_native_('application/json')}
)
Expand All @@ -65,7 +65,7 @@ def test_get_uri_cs_json(self):

def test_get_uri_c_json(self):
res = self.testapp.get(
'/uris/http%3A%2F%2Fpython.com%2Ftrees%2Flarch',
'/uris?uri=http%3A%2F%2Fpython.com%2Ftrees%2Flarch',
{},
{ascii_native_('Accept'): ascii_native_('application/json')}
)
Expand All @@ -78,6 +78,28 @@ def test_get_uri_c_json(self):
self.assertIn('type', data)
self.assertIn('concept_scheme', data)

def test_get_uri_deprecated_way(self):
res1 = self.testapp.get(
'/uris?uri=http://python.com/trees',
{},
{ascii_native_('Accept'): ascii_native_('application/json')}
)
res2 = self.testapp.get(
'/uris/http://python.com/trees',
{},
{ascii_native_('Accept'): ascii_native_('application/json')}
)
self.assertEqual(res1.body, res2.body)

def test_get_uri_no_uri(self):
res = self.testapp.get(
'/uris',
{},
{ascii_native_('Accept'): ascii_native_('application/json')},
status=400
)
self.assertEqual('400 Bad Request', res.status)

def test_get_conceptschemes_json(self):
res = self.testapp.get(
'/conceptschemes',
Expand Down

0 comments on commit 9fcf794

Please sign in to comment.