Ejemplo n.º 1
0
class LanguagesManagerTest(DatamangersTests):

    def setUp(self):
        super(LanguagesManagerTest, self).setUp()
        self.language_manager = LanguagesManager(self.session_maker())

    def test_get(self):
        res = self.language_manager.get('nl')
        self.assertEqual('Dutch', res.name)

    def test_save(self):
        language = Language('de', 'German')
        language = self.language_manager.save(language)
        self.assertEqual('German', language.name)

    def test_delete(self):
        language = self.language_manager.get('en')
        self.language_manager.delete(language)
        self.assertRaises(NoResultFound, self.language_manager.get, 'en')

    def test_get_all(self):
        res = self.language_manager.get_all()
        self.assertEqual(3, len(res))

    def test_get_all_sorted(self):
        res = self.language_manager.get_all_sorted('id', False)
        self.assertEqual('en', res[0].id)

    def test_get_all_sorted_desc(self):
        res = self.language_manager.get_all_sorted('id', True)
        self.assertEqual('nl', res[0].id)

    def test_count_languages(self):
        res = self.language_manager.count_languages('nl')
        self.assertEqual(1, res)
class LanguagesManagerTest(DatamangersTests):
    def setUp(self):
        super(LanguagesManagerTest, self).setUp()
        self.language_manager = LanguagesManager(self.session_maker())

    def test_get(self):
        res = self.language_manager.get('nl')
        self.assertEqual('Dutch', res.name)

    def test_save(self):
        language = Language('de', 'German')
        language = self.language_manager.save(language)
        self.assertEqual('German', language.name)

    def test_delete(self):
        language = self.language_manager.get('en')
        self.language_manager.delete(language)
        self.assertRaises(NoResultFound, self.language_manager.get, 'en')

    def test_get_all(self):
        res = self.language_manager.get_all()
        self.assertGreaterEqual(len(res), 3)

    def test_get_all_sorted(self):
        res = self.language_manager.get_all_sorted('id', False)
        self.assertEqual('en', res[0].id)

    def test_get_all_sorted_desc(self):
        res = self.language_manager.get_all_sorted('id', True)
        self.assertEqual('nl-BE', res[0].id)

    def test_count_languages(self):
        res = self.language_manager.count_languages('nl')
        self.assertEqual(1, res)
Ejemplo n.º 3
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
    }
Ejemplo n.º 4
0
 def setUp(self):
     super(LanguagesManagerTest, self).setUp()
     self.language_manager = LanguagesManager(self.session_maker())
Ejemplo n.º 5
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"
         }]
     }
 def setUp(self):
     super(LanguagesManagerTest, self).setUp()
     self.language_manager = LanguagesManager(self.session_maker())