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