test/unittest_req.py
author Christophe de Vienne <cdevienne@gmail.com>
Wed, 11 Dec 2013 12:22:52 +0100
changeset 9348 eacd02792332
parent 8309 48ef505aa9f9
child 9386 a33da516028f
permissions -rw-r--r--
[req] New method: RequestSessionBase.find(). This method does what find_entities and find_one_entity did, except it returns the resultset itself. In addition, it accepts 'reverse_' arguments and check that the relations actually exists on the entity before executing the query. Also, reimplement find_one_entity and find_entity based on the new function so they benefit from the more complete implementation, and deprecate them. Note: List of values in kwargs are NOT supported in this initial implementation. Closes #3361290
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8190
2a3c1b787688 [vreg] move base registry implementation to logilab.common. Closes #1916014
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 7888
diff changeset
     1
# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4891
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
7888
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    18
4891
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    19
from logilab.common.testlib import TestCase, unittest_main
7888
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    20
from cubicweb import ObjectNotFound
9348
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    21
from cubicweb.req import RequestSessionBase, FindEntityError
6321
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    22
from cubicweb.devtools.testlib import CubicWebTC
6747
63bf61e4e130 [security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    23
from cubicweb import Unauthorized
4891
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    24
7888
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    25
class RequestTC(TestCase):
6321
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    26
    def test_rebuild_url(self):
4891
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    27
        rebuild_url = RequestSessionBase(None).rebuild_url
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6321
diff changeset
    28
        self.assertEqual(rebuild_url('http://logilab.fr?__message=pouet', __message='hop'),
4891
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    29
                          'http://logilab.fr?__message=hop')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6321
diff changeset
    30
        self.assertEqual(rebuild_url('http://logilab.fr', __message='hop'),
4891
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    31
                          'http://logilab.fr?__message=hop')
6340
470d8e828fda [test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6321
diff changeset
    32
        self.assertEqual(rebuild_url('http://logilab.fr?vid=index', __message='hop'),
4891
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    33
                          'http://logilab.fr?__message=hop&vid=index')
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    34
6321
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    35
    def test_build_url(self):
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    36
        req = RequestSessionBase(None)
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    37
        req.from_controller = lambda : 'view'
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    38
        req.relative_path = lambda includeparams=True: None
8309
48ef505aa9f9 [request] gather all base_url logic in a single place (closes #2200756)
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 8190
diff changeset
    39
        req.base_url = lambda secure=None: 'http://testing.fr/cubicweb/'
6321
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    40
        self.assertEqual(req.build_url(), u'http://testing.fr/cubicweb/view')
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    41
        self.assertEqual(req.build_url(None), u'http://testing.fr/cubicweb/view')
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    42
        self.assertEqual(req.build_url('one'), u'http://testing.fr/cubicweb/one')
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    43
        self.assertEqual(req.build_url(param='ok'), u'http://testing.fr/cubicweb/view?param=ok')
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    44
        self.assertRaises(AssertionError, req.build_url, 'one', 'two not allowed')
6595
00cd0b273cf5 [test] fix test to follow recent changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6340
diff changeset
    45
        self.assertRaises(AssertionError, req.build_url, 'view', test=None)
6321
a8a33679f4dd [req] build_url: detect None values in arguments and raise ValueError
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5424
diff changeset
    46
6747
63bf61e4e130 [security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    47
    def test_ensure_no_rql(self):
63bf61e4e130 [security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    48
        req = RequestSessionBase(None)
63bf61e4e130 [security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    49
        self.assertEqual(req.ensure_ro_rql('Any X WHERE X is CWUser'), None)
63bf61e4e130 [security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    50
        self.assertEqual(req.ensure_ro_rql('  Any X WHERE X is CWUser  '), None)
63bf61e4e130 [security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    51
        self.assertRaises(Unauthorized, req.ensure_ro_rql, 'SET X login "toto" WHERE X is CWUser')
63bf61e4e130 [security] fix access control problem
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    52
        self.assertRaises(Unauthorized, req.ensure_ro_rql, '   SET X login "toto" WHERE X is CWUser   ')
4891
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
    53
7888
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    54
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    55
class RequestCWTC(CubicWebTC):
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    56
    def test_view_catch_ex(self):
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    57
        req = self.request()
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    58
        rset = self.execute('CWUser X WHERE X login "hop"')
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    59
        self.assertEqual(req.view('oneline', rset, 'null'), '')
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    60
        self.assertRaises(ObjectNotFound, req.view, 'onelinee', rset, 'null')
e257b4476454 [req] .view should not catch [Object|Registry]NotFound (which is a bug), only NoSelectableObject (closes #1973681)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 6750
diff changeset
    61
9348
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    62
    def test_find_one_entity(self):
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    63
        self.request().create_entity(
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    64
            'CWUser', login=u'cdevienne', upassword=u'cdevienne',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    65
            surname=u'de Vienne', firstname=u'Christophe',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    66
            in_group=self.request().find('CWGroup', name=u'users').one())
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    67
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    68
        self.request().create_entity(
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    69
            'CWUser', login=u'adim', upassword='adim', surname=u'di mascio',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    70
            firstname=u'adrien',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    71
            in_group=self.request().find('CWGroup', name=u'users').one())
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    72
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    73
        u = self.request().find_one_entity('CWUser', login=u'cdevienne')
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    74
        self.assertEqual(u.firstname, u"Christophe")
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    75
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    76
        with self.assertRaises(FindEntityError):
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    77
            self.request().find_one_entity('CWUser', login=u'patanok')
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    78
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    79
        with self.assertRaises(FindEntityError):
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    80
            self.request().find_one_entity('CWUser')
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    81
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    82
    def test_find_entities(self):
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    83
        self.request().create_entity(
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    84
            'CWUser', login=u'cdevienne', upassword=u'cdevienne',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    85
            surname=u'de Vienne', firstname=u'Christophe',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    86
            in_group=self.request().find('CWGroup', name=u'users').one())
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    87
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    88
        self.request().create_entity(
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    89
            'CWUser', login=u'adim', upassword='adim', surname=u'di mascio',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    90
            firstname=u'adrien',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    91
            in_group=self.request().find('CWGroup', name=u'users').one())
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    92
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    93
        l = list(self.request().find_entities('CWUser', login=u'cdevienne'))
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    94
        self.assertEqual(1, len(l))
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    95
        self.assertEqual(l[0].firstname, u"Christophe")
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    96
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    97
        l = list(self.request().find_entities('CWUser', login=u'patanok'))
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    98
        self.assertEqual(0, len(l))
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
    99
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   100
        l = list(self.request().find_entities('CWUser'))
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   101
        self.assertEqual(4, len(l))
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   102
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   103
    def test_find(self):
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   104
        self.request().create_entity(
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   105
            'CWUser', login=u'cdevienne', upassword=u'cdevienne',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   106
            surname=u'de Vienne', firstname=u'Christophe',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   107
            in_group=self.request().find('CWGroup', name=u'users').one())
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   108
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   109
        self.request().create_entity(
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   110
            'CWUser', login=u'adim', upassword='adim', surname=u'di mascio',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   111
            firstname=u'adrien',
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   112
            in_group=self.request().find('CWGroup', name=u'users').one())
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   113
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   114
        u = self.request().find('CWUser', login=u'cdevienne').one()
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   115
        self.assertEqual(u.firstname, u"Christophe")
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   116
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   117
        users = list(self.request().find('CWUser').entities())
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   118
        self.assertEqual(len(users), 4)
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   119
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   120
        groups = list(
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   121
            self.request().find('CWGroup', reverse_in_group=u).entities())
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   122
        self.assertEqual(len(groups), 1)
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   123
        self.assertEqual(groups[0].name, u'users')
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   124
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   125
        users = self.request().find('CWUser', in_group=groups[0]).entities()
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   126
        users = list(users)
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   127
        self.assertEqual(len(users), 2)
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   128
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   129
        with self.assertRaises(AssertionError):
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   130
            self.request().find('CWUser', chapeau=u"melon")
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   131
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   132
        with self.assertRaises(AssertionError):
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   133
            self.request().find('CWUser', reverse_buddy=users[0])
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   134
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   135
        with self.assertRaises(NotImplementedError):
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   136
            self.request().find('CWUser', in_group=[1, 2])
eacd02792332 [req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents: 8309
diff changeset
   137
4891
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   138
if __name__ == '__main__':
90203ec7b3e3 [url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff changeset
   139
    unittest_main()