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 }
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 }
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())