author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 09 Dec 2015 17:44:17 +0100 | |
changeset 11001 | 37c5c9b3b3bf |
parent 10890 | 504a67206fdc |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
2 |
# 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:
4252
diff
changeset
|
3 |
# 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:
4252
diff
changeset
|
4 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
5 |
# 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:
4252
diff
changeset
|
6 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
7 |
# 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:
4252
diff
changeset
|
8 |
# 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:
4252
diff
changeset
|
9 |
# 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:
4252
diff
changeset
|
10 |
# 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:
4252
diff
changeset
|
11 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
12 |
# 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:
4252
diff
changeset
|
13 |
# 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:
4252
diff
changeset
|
14 |
# 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:
4252
diff
changeset
|
15 |
# details. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
16 |
# |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
17 |
# 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:
4252
diff
changeset
|
18 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6315
8ca3ee849bee
[test] fix broken tests and minor cleanups
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
19 |
"""Unit tests for url publishing service""" |
0 | 20 |
|
21 |
import re |
|
22 |
||
23 |
from logilab.common.testlib import unittest_main |
|
24 |
||
25 |
from cubicweb.rset import ResultSet |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
26 |
from cubicweb.devtools.testlib import CubicWebTC |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
27 |
from cubicweb.devtools.fake import FakeRequest |
10582
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
28 |
from cubicweb.web import NotFound, Redirect, views |
0 | 29 |
from cubicweb.web.views.urlrewrite import SimpleReqRewriter |
30 |
||
31 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
32 |
class URLPublisherTC(CubicWebTC): |
0 | 33 |
"""test suite for QSPreProcessor""" |
34 |
||
35 |
def setup_database(self): |
|
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
36 |
with self.admin_access.repo_cnx() as cnx: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
37 |
self.create_user(cnx, u'ÿsaÿe') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
38 |
b = cnx.create_entity('BlogEntry', title=u'hell\'o', content=u'blabla') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
39 |
# take care: Tag's name normalized to lower case |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
40 |
c = cnx.create_entity('Tag', name=u'yo') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
41 |
cnx.execute('SET C tags B WHERE C eid %(c)s, B eid %(b)s', |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
42 |
{'c':c.eid, 'b':b.eid}) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
43 |
cnx.commit() |
1654 | 44 |
|
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
45 |
def process(self, req, url): |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
46 |
return self.app.url_resolver.process(req, url) |
1654 | 47 |
|
0 | 48 |
def test_raw_path(self): |
49 |
"""tests raw path resolution'""" |
|
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
50 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
51 |
self.assertEqual(self.process(req, 'view'), ('view', None)) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
52 |
self.assertEqual(self.process(req, 'edit'), ('edit', None)) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
53 |
self.assertRaises(NotFound, self.process, req, 'whatever') |
0 | 54 |
|
55 |
def test_eid_path(self): |
|
56 |
"""tests eid path resolution""" |
|
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
57 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
58 |
self.assertIsInstance(self.process(req, '123')[1], ResultSet) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
59 |
self.assertEqual(len(self.process(req, '123')[1]), 1) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
60 |
self.assertRaises(NotFound, self.process, req, '123/345') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
61 |
self.assertRaises(NotFound, self.process, req, 'not_eid') |
0 | 62 |
|
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
63 |
def test_rest_path_etype(self): |
0 | 64 |
"""tests the rest path resolution""" |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
65 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
66 |
ctrl, rset = self.process(req, 'CWEType') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
67 |
self.assertEqual(ctrl, 'view') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
68 |
self.assertEqual(rset.description[0][0], 'CWEType') |
10467
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
69 |
self.assertEqual("Any X,AA,AB ORDERBY AB WHERE X is_instance_of CWEType, " |
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
70 |
"X modification_date AA, X name AB", |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
71 |
rset.printable_rql()) |
10582
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
72 |
self.assertEqual(req.form['vid'], 'sameetypelist') |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
73 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
74 |
def test_rest_path_by_attr(self): |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
75 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
76 |
ctrl, rset = self.process(req, 'CWUser/login/admin') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
77 |
self.assertEqual(ctrl, 'view') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
78 |
self.assertEqual(len(rset), 1) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
79 |
self.assertEqual(rset.description[0][0], 'CWUser') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
80 |
self.assertEqual('Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, ' |
10467
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
81 |
'X firstname AA, X login AB, X modification_date AC, ' |
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
82 |
'X surname AD, X login "admin"', |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
83 |
rset.printable_rql()) |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
84 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
85 |
def test_rest_path_unique_attr(self): |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
86 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
87 |
ctrl, rset = self.process(req, 'cwuser/admin') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
88 |
self.assertEqual(ctrl, 'view') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
89 |
self.assertEqual(len(rset), 1) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
90 |
self.assertEqual(rset.description[0][0], 'CWUser') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
91 |
self.assertEqual('Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, ' |
10467
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
92 |
'X firstname AA, X login AB, X modification_date AC, ' |
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
93 |
'X surname AD, X login "admin"', |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
94 |
rset.printable_rql()) |
10582
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
95 |
self.assertEqual(req.form['vid'], 'primary') |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
96 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
97 |
def test_rest_path_eid(self): |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
98 |
with self.admin_access.web_request() as req: |
10890
504a67206fdc
[web/test] Remove use of old test API to silence warning
Rémi Cardona <remi.cardona@logilab.fr>
parents:
10582
diff
changeset
|
99 |
ctrl, rset = self.process(req, 'cwuser/eid/%s' % req.user.eid) |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
100 |
self.assertEqual(ctrl, 'view') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
101 |
self.assertEqual(len(rset), 1) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
102 |
self.assertEqual(rset.description[0][0], 'CWUser') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
103 |
self.assertEqual('Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, ' |
10467
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
104 |
'X firstname AA, X login AB, X modification_date AC, ' |
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
105 |
'X surname AD, X eid %s' % rset[0][0], |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
106 |
rset.printable_rql()) |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
107 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
108 |
def test_rest_path_non_ascii_paths(self): |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
109 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
110 |
ctrl, rset = self.process(req, 'CWUser/login/%C3%BFsa%C3%BFe') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
111 |
self.assertEqual(ctrl, 'view') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
112 |
self.assertEqual(len(rset), 1) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
113 |
self.assertEqual(rset.description[0][0], 'CWUser') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
114 |
self.assertEqual(u'Any X,AA,AB,AC,AD WHERE X is_instance_of CWUser, ' |
10467
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
115 |
u'X firstname AA, X login AB, X modification_date AC, ' |
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
116 |
u'X surname AD, X login "\xffsa\xffe"', |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
117 |
rset.printable_rql()) |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
118 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
119 |
def test_rest_path_quoted_paths(self): |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
120 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
121 |
ctrl, rset = self.process(req, 'BlogEntry/title/hell%27o') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
122 |
self.assertEqual(ctrl, 'view') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
123 |
self.assertEqual(len(rset), 1) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
124 |
self.assertEqual(rset.description[0][0], 'BlogEntry') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
125 |
self.assertEqual(u'Any X,AA,AB,AC WHERE X is_instance_of BlogEntry, ' |
10467
73ea636a5562
[entity] sort fetchattrs when generating rql
Rémi Cardona <remi.cardona@logilab.fr>
parents:
9839
diff
changeset
|
126 |
'X creation_date AA, X modification_date AB, X title AC, ' |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
127 |
'X title "hell\'o"', |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
128 |
rset.printable_rql()) |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
129 |
|
10582
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
130 |
def test_rest_path_use_vid_from_rset(self): |
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
131 |
with self.admin_access.web_request(headers={'Accept': 'application/rdf+xml'}) as req: |
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
132 |
views.VID_BY_MIMETYPE['application/rdf+xml'] = 'rdf' |
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
133 |
try: |
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
134 |
ctrl, rset = self.process(req, 'CWEType') |
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
135 |
finally: |
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
136 |
views.VID_BY_MIMETYPE.pop('application/rdf+xml') |
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
137 |
self.assertEqual(req.form['vid'], 'rdf') |
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
138 |
|
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
139 |
def test_rest_path_errors(self): |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
140 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
141 |
self.assertRaises(NotFound, self.process, req, 'CWUser/eid/30000') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
142 |
self.assertRaises(NotFound, self.process, req, 'Workcases') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
143 |
self.assertRaises(NotFound, self.process, req, 'CWUser/inexistant_attribute/joe') |
1654 | 144 |
|
0 | 145 |
def test_action_path(self): |
146 |
"""tests the action path resolution""" |
|
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
147 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
148 |
self.assertRaises(Redirect, self.process, req, '1/edit') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
149 |
self.assertRaises(Redirect, self.process, req, 'Tag/name/yo/edit') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
150 |
self.assertRaises(Redirect, self.process, req, 'Tag/yo/edit') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
151 |
self.assertRaises(NotFound, self.process, req, 'view/edit') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
152 |
self.assertRaises(NotFound, self.process, req, '1/non_action') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
153 |
self.assertRaises(NotFound, self.process, req, 'CWUser/login/admin/non_action') |
0 | 154 |
|
155 |
def test_regexp_path(self): |
|
156 |
"""tests the regexp path resolution""" |
|
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
157 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
158 |
ctrl, rset = self.process(req, 'add/Task') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
159 |
self.assertEqual(ctrl, 'view') |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
160 |
self.assertEqual(rset, None) |
10582
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
161 |
self.assertEqual(req.form, {'etype': "Task", 'vid': "creation"}) |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
162 |
self.assertRaises(NotFound, self.process, req, 'add/foo/bar') |
0 | 163 |
|
164 |
def test_nonascii_path(self): |
|
165 |
oldrules = SimpleReqRewriter.rules |
|
10582
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
166 |
SimpleReqRewriter.rules = [(re.compile('/\w+', re.U), dict(vid='foo'))] |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
167 |
with self.admin_access.web_request() as req: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
168 |
try: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
169 |
path = str(FakeRequest().url_quote(u'été')) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
170 |
ctrl, rset = self.process(req, path) |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
171 |
self.assertEqual(rset, None) |
10582
bc2f6f0d7433
[urlpublish] RESTPathEvaluator now use vid_from_rset
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
10467
diff
changeset
|
172 |
self.assertEqual(req.form, {'vid': "foo"}) |
9839
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
173 |
finally: |
cf00a6a3f401
[webtests/urlpublisher] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9359
diff
changeset
|
174 |
SimpleReqRewriter.rules = oldrules |
1654 | 175 |
|
0 | 176 |
|
177 |
if __name__ == '__main__': |
|
178 |
unittest_main() |