pyramid_cubicweb/tests/test_tools.py
author Denis Laxalde <denis.laxalde@logilab.fr>
Thu, 07 Jul 2016 14:30:32 +0200
changeset 11630 1400aee10df4
parent 11611 9d2bb6bdb5c8
permissions -rw-r--r--
Port to Python3 (closes #14159555) Add py34 environments to tox configuration (only for CubicWeb >= 3.23). And depend on hg version of cubicweb-pyramid since it is not currently Python3-compatible.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
11550
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     1
from pyramid_cubicweb.tests import PyramidCWTest
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     2
from pyramid_cubicweb import tools
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     3
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     4
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     5
class ToolsTest(PyramidCWTest):
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     6
    anonymous_allowed = True
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     7
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     8
    def test_clone_user(self):
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
     9
        with self.admin_access.repo_cnx() as cnx:
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    10
            user = cnx.find('CWUser', login='anon').one()
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    11
            user.login  # fill the cache
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    12
            clone = tools.clone_user(self.repo, user)
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    13
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    14
            self.assertEqual(clone.eid, user.eid)
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    15
            self.assertEqual(clone.login, user.login)
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    16
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    17
            self.assertEqual(clone.cw_rset.rows, user.cw_rset.rows)
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    18
            self.assertEqual(clone.cw_rset.rql, user.cw_rset.rql)
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    19
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    20
    def test_cnx_attach_entity(self):
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    21
        with self.admin_access.repo_cnx() as cnx:
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    22
            user = cnx.find('CWUser', login='anon').one()
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    23
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    24
        with self.admin_access.repo_cnx() as cnx:
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    25
            tools.cnx_attach_entity(cnx, user)
38ed4c3ac3de [tools] Provide a faster build_user
Christophe de Vienne <christophe@unlish.com>
parents:
diff changeset
    26
            self.assertEqual(user.login, 'anon')
11611
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11550
diff changeset
    27
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11550
diff changeset
    28
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11550
diff changeset
    29
if __name__ == '__main__':
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11550
diff changeset
    30
    from unittest import main
9d2bb6bdb5c8 [tests] add a __main__ handler
David Douard <david.douard@logilab.fr>
parents: 11550
diff changeset
    31
    main()