cubicweb/pyramid/test/test_tools.py
author Yann Voté <yann.vote@logilab.fr>
Mon, 26 Sep 2016 14:52:12 +0200
changeset 11631 faf279e33298
parent 11611 pyramid_cubicweb/tests/test_tools.py@9d2bb6bdb5c8
permissions -rw-r--r--
Merge with pyramid-cubicweb The following tasks have been done: - merge packaging files - merge documentation - move pyramid_cubicweb package at cubicweb/pyramid and update imports accordingly - rename tests directory into test - move pyramid-cubicweb README.rst into README.pyramid.rst until better idea - add a test dependency on unreleased cubicweb-pyramid to have both py27 and py34 tests pass Closes #14023058.

from cubicweb.pyramid.test import PyramidCWTest
from cubicweb.pyramid import tools


class ToolsTest(PyramidCWTest):
    anonymous_allowed = True

    def test_clone_user(self):
        with self.admin_access.repo_cnx() as cnx:
            user = cnx.find('CWUser', login='anon').one()
            user.login  # fill the cache
            clone = tools.clone_user(self.repo, user)

            self.assertEqual(clone.eid, user.eid)
            self.assertEqual(clone.login, user.login)

            self.assertEqual(clone.cw_rset.rows, user.cw_rset.rows)
            self.assertEqual(clone.cw_rset.rql, user.cw_rset.rql)

    def test_cnx_attach_entity(self):
        with self.admin_access.repo_cnx() as cnx:
            user = cnx.find('CWUser', login='anon').one()

        with self.admin_access.repo_cnx() as cnx:
            tools.cnx_attach_entity(cnx, user)
            self.assertEqual(user.login, 'anon')


if __name__ == '__main__':
    from unittest import main
    main()