author | Rémi Cardona <remi.cardona@logilab.fr> |
Tue, 15 Dec 2015 14:12:59 +0100 | |
changeset 10981 | 45bc791275b4 |
parent 9654 | f788e5e7e6ea |
permissions | -rw-r--r-- |
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
1 |
# copyright 2003-2014 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): |
9386
a33da516028f
[req] Return base-url in case https-url is None in base_url()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9348
diff
changeset
|
56 |
|
a33da516028f
[req] Return base-url in case https-url is None in base_url()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9348
diff
changeset
|
57 |
def test_base_url(self): |
a33da516028f
[req] Return base-url in case https-url is None in base_url()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9348
diff
changeset
|
58 |
base_url = self.config['base-url'] |
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
59 |
with self.admin_access.repo_cnx() as session: |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
60 |
self.assertEqual(session.base_url(), base_url) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
61 |
assert 'https-url' not in self.config |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
62 |
self.assertEqual(session.base_url(secure=True), base_url) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
63 |
secure_base_url = base_url.replace('http', 'https') |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
64 |
self.config.global_set_option('https-url', secure_base_url) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
65 |
self.assertEqual(session.base_url(secure=True), secure_base_url) |
9386
a33da516028f
[req] Return base-url in case https-url is None in base_url()
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
9348
diff
changeset
|
66 |
|
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
|
67 |
def test_view_catch_ex(self): |
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
68 |
with self.admin_access.web_request() as req: |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
69 |
rset = req.execute('CWUser X WHERE X login "hop"') |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
70 |
self.assertEqual(req.view('oneline', rset, 'null'), '') |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
71 |
self.assertRaises(ObjectNotFound, req.view, 'onelinee', rset, 'null') |
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
|
72 |
|
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
73 |
def test_find_one_entity(self): |
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
74 |
with self.admin_access.web_request() as req: |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
75 |
req.create_entity( |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
76 |
'CWUser', login=u'cdevienne', upassword=u'cdevienne', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
77 |
surname=u'de Vienne', firstname=u'Christophe', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
78 |
in_group=req.find('CWGroup', name=u'users').one()) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
79 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
80 |
req.create_entity( |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
81 |
'CWUser', login=u'adim', upassword='adim', surname=u'di mascio', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
82 |
firstname=u'adrien', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
83 |
in_group=req.find('CWGroup', name=u'users').one()) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
84 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
85 |
u = req.find_one_entity('CWUser', login=u'cdevienne') |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
86 |
self.assertEqual(u.firstname, u"Christophe") |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
87 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
88 |
with self.assertRaises(FindEntityError): |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
89 |
req.find_one_entity('CWUser', login=u'patanok') |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
90 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
91 |
with self.assertRaises(FindEntityError): |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
92 |
req.find_one_entity('CWUser') |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
93 |
|
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
94 |
def test_find_entities(self): |
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
95 |
with self.admin_access.web_request() as req: |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
96 |
req.create_entity( |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
97 |
'CWUser', login=u'cdevienne', upassword=u'cdevienne', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
98 |
surname=u'de Vienne', firstname=u'Christophe', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
99 |
in_group=req.find('CWGroup', name=u'users').one()) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
100 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
101 |
req.create_entity( |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
102 |
'CWUser', login=u'adim', upassword='adim', surname=u'di mascio', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
103 |
firstname=u'adrien', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
104 |
in_group=req.find('CWGroup', name=u'users').one()) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
105 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
106 |
l = list(req.find_entities('CWUser', login=u'cdevienne')) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
107 |
self.assertEqual(1, len(l)) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
108 |
self.assertEqual(l[0].firstname, u"Christophe") |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
109 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
110 |
l = list(req.find_entities('CWUser', login=u'patanok')) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
111 |
self.assertEqual(0, len(l)) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
112 |
|
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
113 |
l = list(req.find_entities('CWUser')) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
114 |
self.assertEqual(4, len(l)) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
115 |
|
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
116 |
def test_find(self): |
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
117 |
with self.admin_access.web_request() as req: |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
118 |
req.create_entity( |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
119 |
'CWUser', login=u'cdevienne', upassword=u'cdevienne', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
120 |
surname=u'de Vienne', firstname=u'Christophe', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
121 |
in_group=req.find('CWGroup', name=u'users').one()) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
122 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
123 |
req.create_entity( |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
124 |
'CWUser', login=u'adim', upassword='adim', surname=u'di mascio', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
125 |
firstname=u'adrien', |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
126 |
in_group=req.find('CWGroup', name=u'users').one()) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
127 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
128 |
u = req.find('CWUser', login=u'cdevienne').one() |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
129 |
self.assertEqual(u.firstname, u"Christophe") |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
130 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
131 |
users = list(req.find('CWUser').entities()) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
132 |
self.assertEqual(len(users), 4) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
133 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
134 |
groups = list( |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
135 |
req.find('CWGroup', reverse_in_group=u).entities()) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
136 |
self.assertEqual(len(groups), 1) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
137 |
self.assertEqual(groups[0].name, u'users') |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
138 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
139 |
users = req.find('CWUser', in_group=groups[0]).entities() |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
140 |
users = list(users) |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
141 |
self.assertEqual(len(users), 2) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
142 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
143 |
with self.assertRaises(AssertionError): |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
144 |
req.find('CWUser', chapeau=u"melon") |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
145 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
146 |
with self.assertRaises(AssertionError): |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
147 |
req.find('CWUser', reverse_buddy=users[0]) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
148 |
|
9654
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
149 |
with self.assertRaises(NotImplementedError): |
f788e5e7e6ea
[test] update unittest_req to 3.19 api
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
9386
diff
changeset
|
150 |
req.find('CWUser', in_group=[1, 2]) |
9348
eacd02792332
[req] New method: RequestSessionBase.find().
Christophe de Vienne <cdevienne@gmail.com>
parents:
8309
diff
changeset
|
151 |
|
4891
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
152 |
if __name__ == '__main__': |
90203ec7b3e3
[url] new rebuild_url method on base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
diff
changeset
|
153 |
unittest_main() |