Skip to content

Commit

Permalink
Add support for sources
Browse files Browse the repository at this point in the history
  • Loading branch information
koenedaele committed Dec 4, 2015
1 parent 9fcf794 commit cf3d55b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
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)
- Add support for the sources attribute, a new feature in skosprovider 0.6.0

0.6.0 (2015-03-02)
------------------
Expand Down
19 changes: 18 additions & 1 deletion pyramid_skosprovider/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
Concept,
Collection,
Label,
Note
Note,
Source
)


Expand Down Expand Up @@ -59,6 +60,7 @@ def concept_adapter(obj, request):
},
'labels': obj.labels,
'notes': obj.notes,
'sources': obj.sources,
'narrower': obj.narrower,
'broader': obj.broader,
'related': obj.related,
Expand Down Expand Up @@ -86,6 +88,7 @@ def collection_adapter(obj, request):
},
'labels': obj.labels,
'notes': obj.notes,
'sources': obj.sources,
'members': obj.members,
'member_of': obj.member_of,
'superordinates': obj.superordinates,
Expand Down Expand Up @@ -121,7 +124,21 @@ def note_adapter(obj, request):
'markup': obj.markup
}


def source_adapter(obj, request):
'''
Adapter for rendering a :class:`skosprovider.skos.Source` to json.
:param skosprovider.skos.Source obj: The source to be rendered.
:rtype: :class:`dict`
'''
return {
'citation': obj.citation
}


json_renderer.add_adapter(Concept, concept_adapter)
json_renderer.add_adapter(Collection, collection_adapter)
json_renderer.add_adapter(Label, label_adapter)
json_renderer.add_adapter(Note, note_adapter)
json_renderer.add_adapter(Source, source_adapter)
1 change: 1 addition & 0 deletions pyramid_skosprovider/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def get_conceptscheme(self):
'subject': provider.metadata['subject'] if provider.metadata['subject'] else [],
'labels': provider.concept_scheme.labels,
'notes': provider.concept_scheme.notes,
'sources': provider.concept_scheme.sources,
'languages': provider.concept_scheme.languages
}

Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
'notes': [
{'type': 'definition', 'language': 'en', 'note': 'A type of tree.'}
],
'sources': [
{'citation': 'Monthy Python. Episode Three: How to recognise different types of trees from quite a long way away.'}
],
'matches': {
'close': ['http://id.python.org/different/types/of/trees/nr/1/the/larch']
}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def test_get_conceptscheme_json(self):
self.assertIn('subject', data)
self.assertIn('label', data)
self.assertIn('labels', data)
self.assertIn('sources', data)
self.assertEqual(len(data['labels']), 2)
for l in data['labels']:
self.assertIsInstance(l, dict)
Expand Down Expand Up @@ -175,6 +176,7 @@ def test_get_conceptschemes_trees_larch_json(self):
self.assertIn('label', data)
self.assertIn('labels', data)
self.assertIn('notes', data)
self.assertIn('sources', data)
self.assertEqual('concept', data['type'])
self.assertIn('narrower', data)
self.assertIn('broader', data)
Expand Down
4 changes: 4 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def test_concept_adapter(self):
id=larch['id'],
labels=larch['labels'],
notes=larch['notes'],
sources=larch['sources'],
concept_scheme=trees.concept_scheme,
matches=larch['matches']
)
Expand All @@ -86,6 +87,8 @@ def test_concept_adapter(self):
assert 1 == len(concept['matches']['close'])
assert 'subordinate_arrays' in concept
assert 0 == len(concept['subordinate_arrays'])
assert 'sources' in concept
assert 1 == len(concept['sources'])

def test_collection_adapter(self):
from pyramid_skosprovider.utils import collection_adapter
Expand All @@ -108,6 +111,7 @@ def test_collection_adapter(self):
assert not 'matches' in collection
assert 'superordinates' in collection
assert 0 == len(collection['superordinates'])
assert 0 == len(collection['sources'])

def test_json_concept(self):
from pyramid_skosprovider.utils import json_renderer
Expand Down
1 change: 1 addition & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def test_get_conceptscheme(self):
Label('Verschillende soorten bomen', 'prefLabel', 'nl')
],
'notes': [],
'sources': [],
'languages': []
},
cs
Expand Down

0 comments on commit cf3d55b

Please sign in to comment.