unittest_entities.py 2.84 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# coding: utf-8
# copyright 2015 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr -- mailto:contact@logilab.fr
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 2.1 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.

from cubicweb.devtools.testlib import CubicWebTC

class ConceptSchemeTC(CubicWebTC):

    def test_top_concepts(self):
        with self.admin_access.client_cnx() as cnx:
            scheme = cnx.create_entity('ConceptScheme', title=u'some classification')
            c1 = cnx.create_entity('Concept', in_scheme=scheme)
            cnx.create_entity('Label', label=u'hip', language_code=u'fr',
                              pref_label_of=c1)
            c2 = cnx.create_entity('Concept', in_scheme=scheme, broader_concept=c1)
            cnx.create_entity('Label', label=u'hop', language_code=u'fr',
                              pref_label_of=c2)
            cnx.commit()
            self.assertEqual(set(x.eid for x in scheme.top_concepts),
                             set((c1.eid,)))


class ConceptTC(CubicWebTC):
37
38
    def setUp(self):
        super(ConceptTC, self).setUp()
39
40
41
        with self.admin_access.client_cnx() as cnx:
            scheme = cnx.create_entity('ConceptScheme', title=u'some classification')
            c1 = cnx.create_entity('Concept', in_scheme=scheme)
42
            cnx.create_entity('Label', label=u'hîp', language_code=u'fr-CA',
43
44
45
46
47
48
                              pref_label_of=c1)
            cnx.create_entity('Label', label=u'hip', language_code=u'en',
                              pref_label_of=c1)
            cnx.create_entity('Label', label=u'hop', language_code=u'fr',
                              alt_label_of=c1)
            cnx.commit()
49
50
51
52
53
54
55
56
57
58
59
60
        self.c1_eid = c1.eid

    def test_dc_title(self):
        with self.admin_access.client_cnx() as cnx:
            c1 = cnx.entity_from_eid(self.c1_eid)
            self.assertEqual(c1.dc_title(), u'hip')
            cnx.lang = 'fr'
            self.assertEqual(c1.dc_title(), u'hîp')

    def test_labels(self):
        with self.admin_access.client_cnx() as cnx:
            c1 = cnx.entity_from_eid(self.c1_eid)
61
62
            self.assertEqual(c1.labels,
                             {u'en': u'hip', u'fr': u'hîp'})
63
64
65
66
67


if __name__ == '__main__':
    from logilab.common.testlib import unittest_main
    unittest_main()