|
1 # copyright 2018 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # CubicWeb is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
16 # You should have received a copy of the GNU Lesser General Public License along |
|
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
|
18 |
|
19 """Tests for the entity edition""" |
|
20 |
|
21 from cubicweb.devtools.testlib import CubicWebTC |
|
22 from cubicweb.server.edition import EditedEntity |
|
23 |
|
24 |
|
25 class EditedEntityTC(CubicWebTC): |
|
26 """ |
|
27 Test cases for EditedEntity |
|
28 """ |
|
29 |
|
30 def test_clone_cache_reset(self): |
|
31 """ |
|
32 Tests that when an EditedEntity is cloned the caches are reset in the cloned instance |
|
33 :return: Nothing |
|
34 """ |
|
35 # Create an entity, create the EditedEntity and clone it |
|
36 with self.admin_access.cnx() as cnx: |
|
37 affaire = cnx.create_entity("Affaire", sujet=u"toto") |
|
38 ee = EditedEntity(affaire) |
|
39 ee.entity.cw_adapt_to("IWorkflowable") |
|
40 self.assertTrue(ee.entity._cw_related_cache) |
|
41 self.assertTrue(ee.entity._cw_adapters_cache) |
|
42 the_clone = ee.clone() |
|
43 self.assertFalse(the_clone.entity._cw_related_cache) |
|
44 self.assertFalse(the_clone.entity._cw_adapters_cache) |
|
45 cnx.rollback() |
|
46 # Check the attributes |
|
47 with self.admin_access.cnx() as cnx: |
|
48 # Assume a different connection set on the entity |
|
49 self.assertNotEqual(the_clone.entity._cw, cnx) |
|
50 # Use the new connection |
|
51 the_clone.entity._cw = cnx |
|
52 self.assertEqual("toto", the_clone.entity.sujet) |
|
53 |
|
54 |
|
55 if __name__ == '__main__': |
|
56 import unittest |
|
57 unittest.main() |