Skip to content

Commit

Permalink
Expose matches on concepts through the REST interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
koenedaele committed Oct 22, 2014
1 parent 5090fa2 commit fb96c45
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions HISTORY.rst
Expand Up @@ -4,11 +4,13 @@
- Compatibility with skosprovider 0.4.0
- Drop support for Python 2.6 and Python 3.2.
- Expose notes on collections.
- Expose matches on concepts (collections don't have matches).
- Integrate concept scheme information. Concepts and collections passed through
the service now contain the uri of the concept scheme they belong to. The
concept scheme endpoint now also exposes information like a uri, a list of
labels and notes.


0.3.0 (2014-06-24)
------------------

Expand Down
3 changes: 2 additions & 1 deletion pyramid_skosprovider/utils.py
Expand Up @@ -59,7 +59,8 @@ def concept_adapter(obj, request):
'narrower': obj.narrower,
'broader': obj.broader,
'related': obj.related,
'member_of': obj.member_of
'member_of': obj.member_of,
'matches': obj.matches
}


Expand Down
10 changes: 8 additions & 2 deletions tests/fixtures/data.py
Expand Up @@ -15,7 +15,10 @@
],
'notes': [
{'type': 'definition', 'language': 'en', 'note': 'A type of tree.'}
]
],
'matches': {
'close': ['http://id.python.org/different/types/of/trees/nr/1/the/larch']
}
}

chestnut = {
Expand All @@ -30,7 +33,10 @@
'type': 'definition', 'language': 'en',
'note': 'A different type of tree.'
}
]
],
'matches': {
'related': ['http://id.python.org/different/types/of/trees/nr/17/the/other/chestnut']
}
}

species = {
Expand Down
19 changes: 17 additions & 2 deletions tests/test_utils.py
Expand Up @@ -67,7 +67,8 @@ def test_concept_adapter(self):
id=larch['id'],
labels=larch['labels'],
notes=larch['notes'],
concept_scheme=trees.concept_scheme
concept_scheme=trees.concept_scheme,
matches=larch['matches']
)
concept = concept_adapter(c, {})
self.assertIsInstance(concept, dict)
Expand All @@ -77,6 +78,12 @@ def test_concept_adapter(self):
self.assertIn(concept['type'], 'concept')
self.assertEqual(len(concept['labels']), 2)
self._assert_is_labels(concept['labels'])
assert 'matches' in concept
assert 0 == len(concept['matches']['broad'])
assert 0 == len(concept['matches']['narrow'])
assert 0 == len(concept['matches']['related'])
assert 0 == len(concept['matches']['exact'])
assert 1 == len(concept['matches']['close'])

def test_collection_adapter(self):
from pyramid_skosprovider.utils import collection_adapter
Expand All @@ -96,6 +103,7 @@ def test_collection_adapter(self):
self.assertEqual(len(collection['labels']), 2)
self._assert_is_labels(collection['labels'])
self.assertIn('notes', collection)
assert not 'matches' in collection

def test_json_concept(self):
from pyramid_skosprovider.utils import json_renderer
Expand All @@ -104,7 +112,8 @@ def test_json_concept(self):
uri=larch['uri'],
labels=larch['labels'],
notes=larch['notes'],
concept_scheme=trees.concept_scheme
concept_scheme=trees.concept_scheme,
matches=larch['matches']
)
r = json_renderer({})
jsonstring = r(c, {})
Expand All @@ -131,6 +140,11 @@ def test_json_concept(self):
self.assertIsInstance(concept['broader'], list)
self.assertIsInstance(concept['related'], list)
self.assertIsInstance(concept['narrower'], list)
assert 'matches' in concept
for mt in ['broad', 'narrow', 'related', 'close', 'exact']:
assert mt in concept['matches']
assert list == type(concept['matches'][mt])
assert 1 == len(concept['matches']['close'])

def test_json_collection(self):
from pyramid_skosprovider.utils import json_renderer
Expand Down Expand Up @@ -163,3 +177,4 @@ def test_json_collection(self):
self.assertIn('note', n)
self.assertIn('type', n)
self.assertIn('language', n)
assert 'matches' not in coll

0 comments on commit fb96c45

Please sign in to comment.