author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Mon, 26 Aug 2013 16:14:09 +0200 | |
changeset 9256 | 697a8181ba30 |
parent 9211 | d45d66d94baa |
child 9440 | 6880674c1a26 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
3 |
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
5 |
# This file is part of CubicWeb. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
7 |
# CubicWeb is free software: you can redistribute it and/or modify it under the |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
8 |
# terms of the GNU Lesser General Public License as published by the Free |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
9 |
# Software Foundation, either version 2.1 of the License, or (at your option) |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
10 |
# any later version. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
13 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
14 |
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
17 |
# You should have received a copy of the GNU Lesser General Public License along |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1642
diff
changeset
|
19 |
"""unit tests for cubicweb.entities.base module |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1642
diff
changeset
|
20 |
""" |
0 | 21 |
|
22 |
from logilab.common.testlib import unittest_main |
|
23 |
from logilab.common.decorators import clear_cache |
|
24 |
from logilab.common.interface import implements |
|
25 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2660
diff
changeset
|
26 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 27 |
|
28 |
from cubicweb.entities import AnyEntity |
|
29 |
||
30 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2660
diff
changeset
|
31 |
class BaseEntityTC(CubicWebTC): |
0 | 32 |
|
33 |
def setup_database(self): |
|
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7212
diff
changeset
|
34 |
req = self.request() |
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7212
diff
changeset
|
35 |
self.member = self.create_user(req, 'member') |
1642 | 36 |
|
37 |
||
38 |
||
0 | 39 |
class MetadataTC(BaseEntityTC): |
40 |
||
41 |
def test_creator(self): |
|
42 |
self.login(u'member') |
|
4024
6a14cff373c3
more api update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3890
diff
changeset
|
43 |
entity = self.request().create_entity('Bookmark', title=u"hello", path=u'project/cubicweb') |
0 | 44 |
self.commit() |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
45 |
self.assertEqual(entity.creator.eid, self.member.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
46 |
self.assertEqual(entity.dc_creator(), u'member') |
0 | 47 |
|
48 |
def test_type(self): |
|
8899
c7a95ebcc093
[entity] add an official ``cw_etype`` property for entity
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
49 |
#dc_type may be translated |
7980
c85bea091a6c
[test] fix failures introduced by 7951:b7c825b00f64
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7791
diff
changeset
|
50 |
self.assertEqual(self.member.dc_type(), 'CWUser') |
0 | 51 |
|
8899
c7a95ebcc093
[entity] add an official ``cw_etype`` property for entity
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
52 |
def test_cw_etype(self): |
c7a95ebcc093
[entity] add an official ``cw_etype`` property for entity
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
53 |
#cw_etype is never translated |
c7a95ebcc093
[entity] add an official ``cw_etype`` property for entity
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
54 |
self.assertEqual(self.member.cw_etype, 'CWUser') |
c7a95ebcc093
[entity] add an official ``cw_etype`` property for entity
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
55 |
|
1102
054dfee29bfc
some test for meta attributes (XXX should be in yams)
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
56 |
def test_entity_meta_attributes(self): |
054dfee29bfc
some test for meta attributes (XXX should be in yams)
sylvain.thenault@logilab.fr
parents:
1016
diff
changeset
|
57 |
# XXX move to yams |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
58 |
self.assertEqual(self.schema['CWUser'].meta_attributes(), {}) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
59 |
self.assertEqual(dict((str(k), v) for k, v in self.schema['State'].meta_attributes().iteritems()), |
1642 | 60 |
{'description_format': ('format', 'description')}) |
61 |
||
8450
11063635c4e4
[fti] allow usage of custom RQL to fetch entities to index (closes #2410509)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7980
diff
changeset
|
62 |
def test_fti_rql_method(self): |
11063635c4e4
[fti] allow usage of custom RQL to fetch entities to index (closes #2410509)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7980
diff
changeset
|
63 |
eclass = self.vreg['etypes'].etype_class('EmailAddress') |
11063635c4e4
[fti] allow usage of custom RQL to fetch entities to index (closes #2410509)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7980
diff
changeset
|
64 |
self.assertEqual(['Any X, ALIAS, ADDRESS WHERE X is EmailAddress, ' |
11063635c4e4
[fti] allow usage of custom RQL to fetch entities to index (closes #2410509)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7980
diff
changeset
|
65 |
'X alias ALIAS, X address ADDRESS'], |
11063635c4e4
[fti] allow usage of custom RQL to fetch entities to index (closes #2410509)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7980
diff
changeset
|
66 |
eclass.cw_fti_index_rql_queries(self.request())) |
11063635c4e4
[fti] allow usage of custom RQL to fetch entities to index (closes #2410509)
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
7980
diff
changeset
|
67 |
|
0 | 68 |
|
69 |
class EmailAddressTC(BaseEntityTC): |
|
70 |
def test_canonical_form(self): |
|
3204
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
71 |
email1 = self.execute('INSERT EmailAddress X: X address "maarten.ter.huurne@philips.com"').get_entity(0, 0) |
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
72 |
email2 = self.execute('INSERT EmailAddress X: X address "maarten@philips.com"').get_entity(0, 0) |
0b766b8a13e1
#370578: change EmailAddress identical_to/canonical to prefered_form
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2920
diff
changeset
|
73 |
email3 = self.execute('INSERT EmailAddress X: X address "toto@logilab.fr"').get_entity(0, 0) |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8450
diff
changeset
|
74 |
email1.cw_set(prefered_form=email2) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
75 |
self.assertEqual(email1.prefered.eid, email2.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
76 |
self.assertEqual(email2.prefered.eid, email2.eid) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
77 |
self.assertEqual(email3.prefered.eid, email3.eid) |
0 | 78 |
|
79 |
def test_mangling(self): |
|
3831
5eb369d24e7d
benefit from the orm for clearer code
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3830
diff
changeset
|
80 |
email = self.execute('INSERT EmailAddress X: X address "maarten.ter.huurne@philips.com"').get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
81 |
self.assertEqual(email.display_address(), 'maarten.ter.huurne@philips.com') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
82 |
self.assertEqual(email.printable_value('address'), 'maarten.ter.huurne@philips.com') |
0 | 83 |
self.vreg.config.global_set_option('mangle-emails', True) |
9211
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
84 |
try: |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
85 |
self.assertEqual(email.display_address(), 'maarten.ter.huurne at philips dot com') |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
86 |
self.assertEqual(email.printable_value('address'), 'maarten.ter.huurne at philips dot com') |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
87 |
email = self.execute('INSERT EmailAddress X: X address "syt"').get_entity(0, 0) |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
88 |
self.assertEqual(email.display_address(), 'syt') |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
89 |
self.assertEqual(email.printable_value('address'), 'syt') |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
90 |
finally: |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
91 |
self.vreg.config.global_set_option('mangle-emails', False) |
0 | 92 |
|
9211
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
93 |
def test_printable_value_escape(self): |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
94 |
email = self.execute('INSERT EmailAddress X: X address "maarten&ter@philips.com"').get_entity(0, 0) |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
95 |
self.assertEqual(email.printable_value('address'), 'maarten&ter@philips.com') |
d45d66d94baa
[entities] properly escape in EmailAddress.printable_value when format is html. Closes #3064025
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8930
diff
changeset
|
96 |
self.assertEqual(email.printable_value('address', format='text/plain'), 'maarten&ter@philips.com') |
0 | 97 |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
1358
diff
changeset
|
98 |
class CWUserTC(BaseEntityTC): |
1642 | 99 |
|
0 | 100 |
def test_complete(self): |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
101 |
e = self.execute('CWUser X WHERE X login "admin"').get_entity(0, 0) |
0 | 102 |
e.complete() |
103 |
||
104 |
def test_matching_groups(self): |
|
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
105 |
e = self.execute('CWUser X WHERE X login "admin"').get_entity(0, 0) |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
106 |
self.assertTrue(e.matching_groups('managers')) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
107 |
self.assertFalse(e.matching_groups('xyz')) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
108 |
self.assertTrue(e.matching_groups(('xyz', 'managers'))) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
109 |
self.assertFalse(e.matching_groups(('xyz', 'abcd'))) |
0 | 110 |
|
3830
3b6bbb3a3c3e
close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
111 |
def test_dc_title_and_name(self): |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
112 |
e = self.execute('CWUser U WHERE U login "member"').get_entity(0, 0) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
113 |
self.assertEqual(e.dc_title(), 'member') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
114 |
self.assertEqual(e.name(), 'member') |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8450
diff
changeset
|
115 |
e.cw_set(firstname=u'bouah') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
116 |
self.assertEqual(e.dc_title(), 'member') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
117 |
self.assertEqual(e.name(), u'bouah') |
8483
4ba11607d84a
[entity api] unify set_attributes / set_relations into a cw_set method. Closes #2423719
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
8450
diff
changeset
|
118 |
e.cw_set(surname=u'lôt') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
119 |
self.assertEqual(e.dc_title(), 'member') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
120 |
self.assertEqual(e.name(), u'bouah lôt') |
3830
3b6bbb3a3c3e
close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
121 |
|
3b6bbb3a3c3e
close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
122 |
def test_allowed_massmail_keys(self): |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4491
diff
changeset
|
123 |
e = self.execute('CWUser U WHERE U login "member"').get_entity(0, 0) |
3830
3b6bbb3a3c3e
close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
124 |
# Bytes/Password attributes should be omited |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
125 |
self.assertEqual(e.cw_adapt_to('IEmailable').allowed_massmail_keys(), |
3830
3b6bbb3a3c3e
close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
126 |
set(('surname', 'firstname', 'login', 'last_login_time', |
3b6bbb3a3c3e
close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
127 |
'creation_date', 'modification_date', 'cwuri', 'eid')) |
3b6bbb3a3c3e
close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
128 |
) |
3b6bbb3a3c3e
close #472361: omit password and bytes attributes in allowed mass-mailing keys
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3316
diff
changeset
|
129 |
|
7212
040d3597444f
[entities/test] add failing test for cw_instantiate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
130 |
def test_cw_instantiate_object_relation(self): |
040d3597444f
[entities/test] add failing test for cw_instantiate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
131 |
""" a weird non regression test """ |
040d3597444f
[entities/test] add failing test for cw_instantiate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
132 |
e = self.execute('CWUser U WHERE U login "member"').get_entity(0, 0) |
040d3597444f
[entities/test] add failing test for cw_instantiate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
133 |
self.request().create_entity('CWGroup', name=u'logilab', reverse_in_group=e) |
040d3597444f
[entities/test] add failing test for cw_instantiate
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
134 |
|
0 | 135 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2660
diff
changeset
|
136 |
class SpecializedEntityClassesTC(CubicWebTC): |
0 | 137 |
|
138 |
def select_eclass(self, etype): |
|
139 |
# clear selector cache |
|
2650
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
140 |
clear_cache(self.vreg['etypes'], 'etype_class') |
18aec79ec3a3
R [vreg] important refactoring of the vregistry, moving behaviour to end dictionnary (and so leaving room for more flexibility ; keep bw compat ; update api usage in cw
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
141 |
return self.vreg['etypes'].etype_class(etype) |
1642 | 142 |
|
0 | 143 |
def test_etype_class_selection_and_specialization(self): |
144 |
# no specific class for Subdivisions, the default one should be selected |
|
145 |
eclass = self.select_eclass('SubDivision') |
|
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
146 |
self.assertTrue(eclass.__autogenerated__) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
147 |
#self.assertEqual(eclass.__bases__, (AnyEntity,)) |
0 | 148 |
# build class from most generic to most specific and make |
149 |
# sure the most specific is always selected |
|
1358 | 150 |
self.vreg._loadedmods[__name__] = {} |
0 | 151 |
for etype in ('Company', 'Division', 'SubDivision'): |
152 |
class Foo(AnyEntity): |
|
3450
265331a0920c
use __regid__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
3369
diff
changeset
|
153 |
__regid__ = etype |
4491
a0f48c31b58a
kill register_appobject_class method, simplifying autoregistration. Update test accordingly (test which manually registers object should also properly call there __register__ method). Drop the disable-appobjects config file entry: no one used it since its introduction years ago.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
154 |
self.vreg.register(Foo) |
0 | 155 |
eclass = self.select_eclass('SubDivision') |
7791
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
156 |
self.assertTrue(eclass.__autogenerated__) |
31bb51ea5485
[deprecation] fix unittest pending deprecation warnings on failIf/failUnless methods family
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7244
diff
changeset
|
157 |
self.assertFalse(eclass is Foo) |
0 | 158 |
if etype == 'SubDivision': |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
159 |
self.assertEqual(eclass.__bases__, (Foo,)) |
0 | 160 |
else: |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5578
diff
changeset
|
161 |
self.assertEqual(eclass.__bases__[0].__bases__, (Foo,)) |
0 | 162 |
# check Division eclass is still selected for plain Division entities |
163 |
eclass = self.select_eclass('Division') |
|
8899
c7a95ebcc093
[entity] add an official ``cw_etype`` property for entity
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
8694
diff
changeset
|
164 |
self.assertEqual(eclass.cw_etype, 'Division') |
1642 | 165 |
|
0 | 166 |
if __name__ == '__main__': |
167 |
unittest_main() |