Exemple #1
0
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
    }
Exemple #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
    }
class ConceptSchemeManagerTest(DatamangersTests):

    def setUp(self):
        super(ConceptSchemeManagerTest, self).setUp()
        self.conceptscheme_manager = ConceptSchemeManager(self.session_maker())

    def test_get(self):
        res = self.conceptscheme_manager.get(1)
        self.assertEqual('urn:x-skosprovider:trees', res.uri)

    def test_find(self):
        query = {'type': 'concept', 'label': 'es'}
        res = self.conceptscheme_manager.find(1, query)
        self.assertEqual(1, len(res))

    def test_get_concepts_for_scheme_tree(self):
        res = self.conceptscheme_manager.get_concepts_for_scheme_tree(2)
        self.assertEqual(1, len(res))

    def test_get_collections_for_scheme_tree(self):
        res = self.conceptscheme_manager.get_collections_for_scheme_tree(2)
        self.assertEqual(1, len(res))

    def test_get_all(self):
        res = self.conceptscheme_manager.get_all(2)
        self.assertEqual(10, len(res))

    def test_save(self):
        local_session = self.session_maker()
        conceptscheme = local_session.query(ConceptScheme).filter(Concept.id == 1).first()
        conceptscheme = self.conceptscheme_manager.save(conceptscheme)
        self.assertIsNotNone(conceptscheme.id)
        local_session.close()
class ConceptSchemeManagerTest(DatamangersTests):
    def setUp(self):
        super(ConceptSchemeManagerTest, self).setUp()
        self.conceptscheme_manager = ConceptSchemeManager(self.session_maker())

    def test_get(self):
        res = self.conceptscheme_manager.get(1)
        self.assertEqual('urn:x-skosprovider:trees', res.uri)

    def test_find(self):
        query = {'type': 'concept', 'label': 'es'}
        res = self.conceptscheme_manager.find(1, query)
        self.assertEqual(1, len(res))

    def test_get_concepts_for_scheme_tree(self):
        res = self.conceptscheme_manager.get_concepts_for_scheme_tree(2)
        self.assertEqual(1, len(res))

    def test_get_collections_for_scheme_tree(self):
        res = self.conceptscheme_manager.get_collections_for_scheme_tree(2)
        self.assertEqual(1, len(res))

    def test_get_all(self):
        res = self.conceptscheme_manager.get_all(2)
        self.assertEqual(10, len(res))

    def test_save(self):
        local_session = self.session_maker()
        conceptscheme = local_session.query(ConceptScheme).filter(Concept.id == 1).first()
        conceptscheme = self.conceptscheme_manager.save(conceptscheme)
        self.assertIsNotNone(conceptscheme.id)
        local_session.close()
 def setUp(self):
     super(ConceptSchemeManagerTest, self).setUp()
     self.conceptscheme_manager = ConceptSchemeManager(self.session_maker())
 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"
         }]
     }
 def setUp(self):
     super(ConceptSchemeManagerTest, self).setUp()
     self.conceptscheme_manager = ConceptSchemeManager(self.session_maker())