Beispiel #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
    }
Beispiel #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 AuditManagerTest(DatamangersTests):
    def setUp(self):
        super(AuditManagerTest, self).setUp()
        self.audit_manager = AuditManager(self.session_maker())

    @patch('atramhasis.data.datamanagers.date', Mock(today=Mock(return_value=date(2015, 8, 1))))
    def test_get_first_day(self):
        self.assertEqual('2015-07-31', self.audit_manager._get_first_day('last_day'))
        self.assertEqual('2015-07-25', self.audit_manager._get_first_day('last_week'))
        self.assertEqual('2015-07-01', self.audit_manager._get_first_day('last_month'))
        self.assertEqual('2014-08-01', self.audit_manager._get_first_day('last_year'))

    @patch('atramhasis.data.datamanagers.date', Mock(today=Mock(return_value=date(2015, 9, 15))))
    def test_get_most_popular_concepts_for_conceptscheme(self):
        self.assertListEqual([{'concept_id': 1, 'scheme_id': 1}, {'concept_id': 2, 'scheme_id': 1}],
                             self.audit_manager.get_most_popular_concepts_for_conceptscheme(1, 5, 'last_month'))
        self.assertListEqual([{'concept_id': 2, 'scheme_id': 2}],
                             self.audit_manager.get_most_popular_concepts_for_conceptscheme(2, 5, 'last_month'))
        self.assertListEqual([{'concept_id': 1, 'scheme_id': 1}],
                             self.audit_manager.get_most_popular_concepts_for_conceptscheme(1, 1, 'last_month'))
        self.assertListEqual([],
                             self.audit_manager.get_most_popular_concepts_for_conceptscheme(1, 5, 'last_day'))
 def setUp(self):
     super(AuditManagerTest, self).setUp()
     self.audit_manager = AuditManager(self.session_maker())
 def setUp(self):
     super(AuditManagerTest, self).setUp()
     self.audit_manager = AuditManager(self.session_maker())