Пример #1
0
 def test_json_collection(self):
     from pyramid_skosprovider.renderers import json_renderer
     c = Collection(
         id=species['id'],
         uri=species['uri'],
         labels=species['labels'],
         notes=species['notes'],
         members=[larch['id']],
         concept_scheme=trees.concept_scheme
     )
     r = json_renderer({})
     m = Mock()
     config = {
         'get_provider.return_value.get_by_id.return_value': Concept(id=larch['id'], uri=larch['uri'], labels=larch['labels'])
     }
     m.configure_mock(**config)
     request = testing.DummyRequest()
     request.skos_registry = m
     sys = {}
     sys['request'] = request
     jsonstring = r(c, sys)
     coll = json.loads(jsonstring)
     assert isinstance(coll, dict)
     assert coll['id'] == 3
     assert coll['uri'] == 'http://python.com/trees/species'
     assert isinstance(coll['label'], text_type)
     assert coll['type'] == 'collection'
     assert isinstance(coll['labels'], list)
     assert len(coll['labels']) == 2
     for l in coll['labels']:
         assert 'label' in l
         assert 'type' in l
         assert 'language' in l
     assert len(coll['notes']) == 1
     for n in coll['notes']:
         assert 'note' in n
         assert 'type' in n
         assert 'language' in n
         assert 'markup' in n
     assert len(coll['members']) == 1
     m = coll['members'][0]
     assert 'id' in m
     assert 'uri' in m
     assert 'type' in m
     assert 'label' in m
     assert 'matches' not in coll
Пример #2
0
 def test_json_concept(self):
     from pyramid_skosprovider.renderers import json_renderer
     c = Concept(
         id=larch['id'],
         uri=larch['uri'],
         labels=larch['labels'],
         notes=larch['notes'],
         concept_scheme=trees.concept_scheme,
         matches=larch['matches']
     )
     r = json_renderer({})
     request = testing.DummyRequest()
     m = Mock()
     request.skos_registry = m
     sys = {}
     sys['request'] = request
     jsonstring = r(c, sys)
     concept = json.loads(jsonstring)
     self.assertIsInstance(concept, dict)
     self.assertEqual(concept['id'], 1)
     self.assertEqual(concept['uri'], 'http://python.com/trees/larch')
     self.assertIsInstance(concept['label'], text_type)
     self.assertEqual(concept['type'], 'concept')
     self.assertIsInstance(concept['labels'], list)
     self.assertEqual(len(concept['labels']), 2)
     for l in concept['labels']:
         self.assertIsInstance(l, dict)
         self.assertIn('label', l)
         self.assertIn('type', l)
         self.assertIn('language', l)
     self.assertIsInstance(concept['notes'], list)
     self.assertEqual(len(concept['notes']), 1)
     for n in concept['notes']:
         self.assertIsInstance(n, dict)
         self.assertIn('note', n)
         self.assertIn('type', n)
         self.assertIn('language', n)
         self.assertIn('markup', n)
     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'])
Пример #3
0
 def test_json_collection(self):
     from pyramid_skosprovider.renderers import json_renderer
     c = Collection(id=species['id'],
                    uri=species['uri'],
                    labels=species['labels'],
                    notes=species['notes'],
                    members=[larch['id']],
                    concept_scheme=trees.concept_scheme)
     r = json_renderer({})
     m = Mock()
     config = {
         'get_provider.return_value.get_by_id.return_value':
         Concept(id=larch['id'], uri=larch['uri'], labels=larch['labels'])
     }
     m.configure_mock(**config)
     request = testing.DummyRequest()
     request.skos_registry = m
     sys = {}
     sys['request'] = request
     jsonstring = r(c, sys)
     coll = json.loads(jsonstring)
     assert isinstance(coll, dict)
     assert coll['id'] == 3
     assert coll['uri'] == 'http://python.com/trees/species'
     assert isinstance(coll['label'], text_type)
     assert coll['type'] == 'collection'
     assert isinstance(coll['labels'], list)
     assert len(coll['labels']) == 3
     for l in coll['labels']:
         assert 'label' in l
         assert 'type' in l
         assert 'language' in l
     assert len(coll['notes']) == 1
     for n in coll['notes']:
         assert 'note' in n
         assert 'type' in n
         assert 'language' in n
         assert 'markup' in n
     assert len(coll['members']) == 1
     m = coll['members'][0]
     assert 'id' in m
     assert 'uri' in m
     assert 'type' in m
     assert 'label' in m
     assert 'matches' not in coll
Пример #4
0
 def test_json_concept(self):
     from pyramid_skosprovider.renderers import json_renderer
     c = Concept(id=larch['id'],
                 uri=larch['uri'],
                 labels=larch['labels'],
                 notes=larch['notes'],
                 concept_scheme=trees.concept_scheme,
                 matches=larch['matches'])
     r = json_renderer({})
     request = testing.DummyRequest()
     m = Mock()
     request.skos_registry = m
     sys = {}
     sys['request'] = request
     jsonstring = r(c, sys)
     concept = json.loads(jsonstring)
     self.assertIsInstance(concept, dict)
     self.assertEqual(concept['id'], 1)
     self.assertEqual(concept['uri'], 'http://python.com/trees/larch')
     self.assertIsInstance(concept['label'], text_type)
     self.assertEqual(concept['type'], 'concept')
     self.assertIsInstance(concept['labels'], list)
     self.assertEqual(len(concept['labels']), 3)
     for l in concept['labels']:
         self.assertIsInstance(l, dict)
         self.assertIn('label', l)
         self.assertIn('type', l)
         self.assertIn('language', l)
     self.assertIsInstance(concept['notes'], list)
     self.assertEqual(len(concept['notes']), 1)
     for n in concept['notes']:
         self.assertIsInstance(n, dict)
         self.assertIn('note', n)
         self.assertIn('type', n)
         self.assertIn('language', n)
         self.assertIn('markup', n)
     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'])