skeleton/test/test_CUBENAME.py.tmpl
author Julien Cristau <julien.cristau@logilab.fr>
Thu, 10 Dec 2015 16:58:45 +0100
changeset 10997 da712d3f0601
parent 10214 88f60d4b9952
permissions -rw-r--r--
Bring back the separate web-side entity cache Prior to changeset 635cfac73d28 "[repoapi] fold ClientConnection into Connection", we had two entity caches: one on the client/dbapi/web side, and one on the server/repo side. This is a waste, but it is actually needed as long as we have the magic _cw attribute on entities which must sometimes be a request and sometimes a cnx. Removing the duplication caused weird problems with entity._cw alternating between both types of objects, which is unexpected by both the repo and the web sides. We add an entity cache on ConnectionCubicWebRequestBase, separate from the Connection's, and bring back the _cw_update_attr_cache/dont-cache-attrs mechanism, to let the server/edition code let caches know which attributes have been modified Entity.as_rset can be cached again, as ResultSet no longer modifies the entity when fetching it from a cache. Contrary to the pre-3.21 code, _cw_update_attr_cache now handles web requests and connections in the same way (otherwise the cache ends up with wrong values if a hook modifies attributes), but dont-cache-attrs is never set for (inlined) relations. Closes #6863543
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5915
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
     1
# copyright %(year)s %(author)s, all rights reserved.
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
     2
# contact %(author-web-site)s -- mailto:%(author-email)s
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4212
diff changeset
     3
#
5915
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
     4
%(long-license)s
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
     5
"""%(distname)s automatic tests
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
     6
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
     7
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
     8
uncomment code below if you want to activate automatic test for your cube:
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
     9
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    10
.. sourcecode:: python
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    11
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    12
    from cubicweb.devtools.testlib import AutomaticWebTest
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    13
5915
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    14
    class AutomaticWebTest(AutomaticWebTest):
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    15
        '''provides `to_test_etypes` and/or `list_startup_views` implementation
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    16
        to limit test scope
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    17
        '''
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    18
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    19
        def to_test_etypes(self):
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    20
            '''only test views for entities of the returned types'''
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    21
            return set(('My', 'Cube', 'Entity', 'Types'))
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    22
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    23
        def list_startup_views(self):
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    24
            '''only test startup views of the returned identifiers'''
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    25
            return ('some', 'startup', 'views')
1977
606923dff11b big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 0
diff changeset
    26
"""
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
5915
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    28
from cubicweb.devtools import testlib
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    29
10214
88f60d4b9952 [newcube] Make the generated code PEP-8 compliant
Christophe de Vienne <christophe@unlish.com>
parents: 6898
diff changeset
    30
5915
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    31
class DefaultTC(testlib.CubicWebTC):
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
    def test_something(self):
6898
60cbb2b39ca9 [skel] try to generate warning free stub...
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5915
diff changeset
    33
        self.skipTest('this cube has no test')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
if __name__ == '__main__':
5915
e6cc50932720 [skel] nicer test file skeleton
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5424
diff changeset
    37
    from logilab.common.testlib import unittest_main
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
    unittest_main()