コード例 #1
0
ファイル: db.py プロジェクト: lab9k/atramhasis
def data_managers(request):
    """
    Generate a datamanager with a database session and register a cleanup handler.

    :param pyramid.request.Request request: The request this db session will
        be tied to.
    :returns: A dictionary containing different
        :class:`datamanagers <atramhasis.data.datamanagers.DataManager>`.
    """
    session = request.registry.dbmaker()
    skos_manager = SkosManager(session)
    conceptscheme_manager = ConceptSchemeManager(session)
    languages_manager = LanguagesManager(session)
    audit_manager = AuditManager(session)

    def cleanup(request):
        session.close()

    request.add_finished_callback(cleanup)

    return {
        'skos_manager': skos_manager,
        'conceptscheme_manager': conceptscheme_manager,
        'languages_manager': languages_manager,
        'audit_manager': audit_manager
    }
コード例 #2
0
def data_managers(request):
    session_mock = Mock()
    session_mock.query = Mock(side_effect=create_query_mock)
    skos_manager = SkosManager(session_mock)
    conceptscheme_manager = ConceptSchemeManager(session_mock)
    audit_manager = AuditManager(session_mock)
    return {
        'skos_manager': skos_manager,
        'conceptscheme_manager': conceptscheme_manager,
        'audit_manager': audit_manager
    }
コード例 #3
0
class SkosManagerTest(DatamangersTests):

    def setUp(self):
        super(SkosManagerTest, self).setUp()
        self.skos_manager = SkosManager(self.session_maker())

    def test_get_thing(self):
        res = self.skos_manager.get_thing(1, 1)
        self.assertEqual('urn:x-skosprovider:trees/1', res.uri)

    def test_save(self):
        thing = Concept()
        thing.concept_id = 123
        thing.conceptscheme_id = 1
        thing = self.skos_manager.save(thing)
        self.assertIsNotNone(thing.id)

    def test_delete_thing(self):
        thing = self.skos_manager.get_thing(1, 1)
        self.skos_manager.delete_thing(thing)
        self.assertRaises(NoResultFound, self.skos_manager.get_thing, 1, 1)

    def test_get_by_list_type(self):
        res = self.skos_manager.get_by_list_type(LabelType)
        self.assertEqual(3, len(res))

    def test_get_match_type(self):
        matchType= self.skos_manager.get_match_type('narrowMatch')
        self.assertEqual('narrowMatch', matchType.name)

    def test_get_match(self):
        match = self.skos_manager.get_match('urn:test', 'narrowMatch', 1)
        self.assertEqual('urn:test', match.uri)

    def test_get_all_label_types(self):
        res = self.skos_manager.get_all_label_types()
        self.assertEqual(3, len(res))

    def test_get_next_cid(self):
        res = self.skos_manager.get_next_cid(1)
        self.assertIsNotNone(res)
コード例 #4
0
class SkosManagerTest(DatamangersTests):
    def setUp(self):
        super(SkosManagerTest, self).setUp()
        self.skos_manager = SkosManager(self.session_maker())

    def test_get_thing(self):
        res = self.skos_manager.get_thing(1, 1)
        self.assertEqual('urn:x-skosprovider:trees/1', res.uri)

    def test_save(self):
        thing = Concept()
        thing.concept_id = 123
        thing.conceptscheme_id = 1
        thing = self.skos_manager.save(thing)
        self.assertIsNotNone(thing.id)

    def test_delete_thing(self):
        thing = self.skos_manager.get_thing(1, 1)
        self.skos_manager.delete_thing(thing)
        self.assertRaises(NoResultFound, self.skos_manager.get_thing, 1, 1)

    def test_get_by_list_type(self):
        res = self.skos_manager.get_by_list_type(LabelType)
        self.assertEqual(3, len(res))

    def test_get_match_type(self):
        matchType = self.skos_manager.get_match_type('narrowMatch')
        self.assertEqual('narrowMatch', matchType.name)

    def test_get_match(self):
        match = self.skos_manager.get_match('urn:test', 'narrowMatch', 1)
        self.assertEqual('urn:test', match.uri)

    def test_get_all_label_types(self):
        res = self.skos_manager.get_all_label_types()
        self.assertEqual(3, len(res))

    def test_get_next_cid(self):
        res = self.skos_manager.get_next_cid(1)
        self.assertIsNotNone(res)
コード例 #5
0
 def setUp(self):
     self.skos_manager = SkosManager(session_maker())
     self.concept = Concept()
     self.concept.concept_id = 1
     self.concept.conceptscheme_id = 1
     self.collection = Collection()
     self.collection.concept_id = 0
     self.collection.conceptscheme_id = 1
     self.conceptscheme = ConceptScheme()
     self.conceptscheme.id = 1
     member_concept_1 = Concept()
     member_concept_1.concept_id = 5
     member_concept_1.conceptscheme_id = 1
     member_concept_2 = Collection()
     member_concept_2.concept_id = 6
     member_concept_2.conceptscheme_id = 1
     self.collection.members.add(member_concept_1)
     self.collection.members.add(member_concept_2)
     self.concept.narrower_concepts.add(member_concept_1)
     self.concept.narrower_collections.add(member_concept_2)
コード例 #6
0
 def setUp(self):
     super(SkosManagerTest, self).setUp()
     self.skos_manager = SkosManager(self.session_maker())
コード例 #7
0
 def setUp(self):
     self.config = testing.setUp()
     self.request = testing.DummyRequest()
     session = session_maker()
     self.request.data_managers = {
         'skos_manager': SkosManager(session),
         'conceptscheme_manager': ConceptSchemeManager(session),
         'languages_manager': LanguagesManager(session)
     }
     self.concept_schema = ConceptSchema(
         validator=concept_schema_validator).bind(request=self.request,
                                                  conceptscheme_id=1)
     self.language = LanguageTag(validator=languagetag_validator).bind(
         request=self.request, new=True)
     self.conceptscheme_schema = ConceptSchemeSchema(
         validator=conceptscheme_schema_validator).bind(
             request=self.request)
     self.json_concept = {
         "narrower": [{
             "id": 8
         }, {
             "id": 7
         }, {
             "id": 9
         }],
         "label": "Belgium",
         "type": "concept",
         "id": 4,
         "broader": [{
             "id": 2
         }],
         "related": [{
             "id": 5
         }],
         "labels": [{
             "label": "Belgium",
             "type": "prefLabel",
             "language": "en"
         }],
         "notes": [{
             "note": "een notitie",
             "type": "note",
             "language": "nl"
         }],
         "sources": [{
             "citation": "Van Daele K. 2014"
         }],
         "member_of": [{
             "id": 666
         }]
     }
     self.json_collection = {
         "id":
         0,
         "labels": [{
             "language": "nl-BE",
             "label": "Stijlen en culturen",
             "type": "prefLabel"
         }],
         "type":
         "collection",
         "label":
         "Stijlen en culturen",
         "members": [{
             "id": 61
         }, {
             "id": 60
         }],
         "notes": [{
             "note": "een notitie",
             "type": "note",
             "language": "nl"
         }],
         "member_of": [{
             "id": 666
         }]
     }
     self.json_conceptscheme = {
         "labels": [{
             "language": "nl-BE",
             "label": "Stijlen en culturen",
             "type": "prefLabel"
         }],
         "label":
         "Stijlen en culturen",
         "notes": [{
             "note": "een notitie",
             "type": "note",
             "language": "nl"
         }],
         "sources": [{
             "citation": "Van Daele K. 2014"
         }]
     }
コード例 #8
0
 def setUp(self):
     super(SkosManagerTest, self).setUp()
     self.skos_manager = SkosManager(self.session_maker())