From 3953e1e56015fbe1837201a5d47d04582ecf8143 Mon Sep 17 00:00:00 2001 From: Koen Van Daele Date: Tue, 8 Dec 2015 14:14:17 +0100 Subject: [PATCH] More fixes and tests for source notes. Refs #199 --- atramhasis/utils.py | 10 +++++++++- tests/test_functional.py | 7 ++++++- tests/test_utils.py | 13 ++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/atramhasis/utils.py b/atramhasis/utils.py index b18e41f2..2e19faf2 100644 --- a/atramhasis/utils.py +++ b/atramhasis/utils.py @@ -5,7 +5,7 @@ from collections import deque from pyramid.httpexceptions import HTTPMethodNotAllowed -from skosprovider.skos import Concept, Collection, Label, Note, ConceptScheme +from skosprovider.skos import Concept, Collection, Label, Note, Source, ConceptScheme from skosprovider_sqlalchemy.providers import SQLAlchemyProvider @@ -28,6 +28,10 @@ def from_thing(thing): Label(l.label, l.labeltype_id, l.language_id) for l in thing.labels ], + sources=[ + Source(s.citation) + for s in thing.sources + ], members=[member.concept_id for member in thing.members] if hasattr(thing, 'members') else [], member_of=[c.concept_id for c in thing.member_of], superordinates=[broader_concept.concept_id for broader_concept in thing.broader_concepts] @@ -51,6 +55,10 @@ def from_thing(thing): Note(n.note, n.notetype_id, n.language_id) for n in thing.notes ], + sources=[ + Source(s.citation) + for s in thing.sources + ], broader=[c.concept_id for c in thing.broader_concepts], narrower=[c.concept_id for c in thing.narrower_concepts], related=[c.concept_id for c in thing.related_concepts], diff --git a/tests/test_functional.py b/tests/test_functional.py index 2393eb2a..48a4bbdf 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -47,7 +47,12 @@ "label": "The Larch" } ], - "notes": [] + "notes": [], + "sources": [ + { + "citation": "Python, M.: Episode Three: How to recognise different types of trees from quite a long way away." + } + ] } json_value_relations = { diff --git a/tests/test_utils.py b/tests/test_utils.py index 30db3056..549d91b8 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -3,7 +3,12 @@ from pyramid.httpexceptions import HTTPMethodNotAllowed from skosprovider.providers import DictionaryProvider -from skosprovider_sqlalchemy.models import Concept, Collection, Note, Label, ConceptScheme, Match, MatchType +from skosprovider_sqlalchemy.models import ( + Concept, Collection, + Note, Label, Source, + ConceptScheme, + Match, MatchType +) from skosprovider_sqlalchemy.providers import SQLAlchemyProvider from skosprovider.skos import( Concept as SkosConcept, @@ -59,6 +64,11 @@ def setUp(self): labels.append(label3) self.concept.labels = labels + sources = [] + source = Source(citation='Kinsella S. & Carlisle P. 2015: Alice.') + sources.append(source) + self.concept.sources = sources + matches = [] match1 = Match() match1.uri ='urn:test' @@ -86,6 +96,7 @@ def test_thing_to_concept(self): self.assertEqual(skosconcept.id, 101) self.assertEqual(len(skosconcept.labels), 3) self.assertEqual(len(skosconcept.notes), 2) + self.assertEqual(len(skosconcept.sources), 1) self.assertEqual(skosconcept.uri, 'urn:x-atramhasis-demo:TREES:101') def test_thing_to_collection(self):