author | Adrien Di Mascio <Adrien.DiMascio@logilab.fr> |
Wed, 01 Aug 2012 09:20:47 +0200 | |
branch | stable |
changeset 8504 | f21c72928662 |
parent 7794 | aed065b97f12 |
child 9359 | 31a1813d53f3 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
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
|
2 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
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 |
0 | 28 |
from cubicweb.web import NotFound, Redirect |
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): |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
36 |
req = self.request() |
7244
a918f76441ce
fix tests broken by fcb8932082a5 (continued)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents:
7017
diff
changeset
|
37 |
self.create_user(req, u'ÿsaÿe') |
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
38 |
b = req.create_entity('BlogEntry', title=u'hell\'o', content=u'blabla') |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
39 |
c = req.create_entity('Tag', name=u'yo') # take care: Tag's name normalized to lower case |
5174
78438ad513ca
#759035: Automate addition of eid cachekey in RQL analysis
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
40 |
self.execute('SET C tags B WHERE C eid %(c)s, B eid %(b)s', {'c':c.eid, 'b':b.eid}) |
1654 | 41 |
|
0 | 42 |
def process(self, url): |
43 |
req = self.req = self.request() |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
44 |
return self.app.url_resolver.process(req, url) |
1654 | 45 |
|
0 | 46 |
def test_raw_path(self): |
47 |
"""tests raw path resolution'""" |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
48 |
self.assertEqual(self.process('view'), ('view', None)) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
49 |
self.assertEqual(self.process('edit'), ('edit', None)) |
0 | 50 |
self.assertRaises(NotFound, self.process, 'whatever') |
51 |
||
52 |
def test_eid_path(self): |
|
53 |
"""tests eid path resolution""" |
|
54 |
self.assertIsInstance(self.process('123')[1], ResultSet) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
55 |
self.assertEqual(len(self.process('123')[1]), 1) |
0 | 56 |
self.assertRaises(NotFound, self.process, '123/345') |
57 |
self.assertRaises(NotFound, self.process, 'not_eid') |
|
58 |
||
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
59 |
def test_rest_path_etype(self): |
0 | 60 |
"""tests the rest path resolution""" |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
61 |
ctrl, rset = self.process('CWEType') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
62 |
self.assertEqual(ctrl, 'view') |
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 |
self.assertEqual(rset.description[0][0], 'CWEType') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
64 |
self.assertEqual(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
|
65 |
"Any X,AA,AB ORDERBY AA WHERE X is CWEType, X name AA, X modification_date AB") |
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
66 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
67 |
def test_rest_path_by_attr(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
68 |
ctrl, rset = self.process('CWUser/login/admin') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
69 |
self.assertEqual(ctrl, 'view') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
70 |
self.assertEqual(len(rset), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
71 |
self.assertEqual(rset.description[0][0], 'CWUser') |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7244
diff
changeset
|
72 |
self.assertEqual(rset.printable_rql(), 'Any X,AA,AB,AC,AD WHERE X is CWUser, X login AA, X firstname AB, X surname AC, X modification_date AD, X login "admin"') |
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_unique_attr(self): |
1654 | 75 |
ctrl, rset = self.process('cwuser/admin') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
76 |
self.assertEqual(ctrl, 'view') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
77 |
self.assertEqual(len(rset), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
78 |
self.assertEqual(rset.description[0][0], 'CWUser') |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7244
diff
changeset
|
79 |
self.assertEqual(rset.printable_rql(), 'Any X,AA,AB,AC,AD WHERE X is CWUser, X login AA, X firstname AB, X surname AC, X modification_date AD, X login "admin"') |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
80 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
81 |
def test_rest_path_eid(self): |
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
82 |
ctrl, rset = self.process('cwuser/eid/%s' % self.user().eid) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
83 |
self.assertEqual(ctrl, 'view') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
84 |
self.assertEqual(len(rset), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
85 |
self.assertEqual(rset.description[0][0], 'CWUser') |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7244
diff
changeset
|
86 |
self.assertEqual(rset.printable_rql(), 'Any X,AA,AB,AC,AD WHERE X is CWUser, X login AA, X firstname AB, X surname AC, X modification_date AD, X eid %s' % rset[0][0]) |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
87 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
88 |
def test_rest_path_non_ascii_paths(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
89 |
ctrl, rset = self.process('CWUser/login/%C3%BFsa%C3%BFe') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
90 |
self.assertEqual(ctrl, 'view') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
91 |
self.assertEqual(len(rset), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
92 |
self.assertEqual(rset.description[0][0], 'CWUser') |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7244
diff
changeset
|
93 |
self.assertEqual(rset.printable_rql(), u'Any X,AA,AB,AC,AD WHERE X is CWUser, X login AA, X firstname AB, X surname AC, X modification_date AD, X login "\xffsa\xffe"') |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
94 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
95 |
def test_rest_path_quoted_paths(self): |
0 | 96 |
ctrl, rset = self.process('BlogEntry/title/hell%27o') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
97 |
self.assertEqual(ctrl, 'view') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
98 |
self.assertEqual(len(rset), 1) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
99 |
self.assertEqual(rset.description[0][0], 'BlogEntry') |
7794
aed065b97f12
refactor entity fetch_rql method to use a RQL syntax tree instead of RQL strings ; closes #1585650
Florent Cayré <florent.cayre@gmail.com>
parents:
7244
diff
changeset
|
100 |
self.assertEqual(rset.printable_rql(), u'Any X,AA,AB,AC WHERE X is BlogEntry, X creation_date AA, X title AB, X modification_date AC, X title "hell\'o"') |
7017
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
101 |
|
cd2ea273007a
[web test] fix some tests broken by recent (and various) changesets
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
102 |
def test_rest_path_errors(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
103 |
self.assertRaises(NotFound, self.process, 'CWUser/eid/30000') |
0 | 104 |
self.assertRaises(NotFound, self.process, 'Workcases') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
105 |
self.assertRaises(NotFound, self.process, 'CWUser/inexistant_attribute/joe') |
1654 | 106 |
|
0 | 107 |
def test_action_path(self): |
108 |
"""tests the action path resolution""" |
|
109 |
self.assertRaises(Redirect, self.process, '1/edit') |
|
110 |
self.assertRaises(Redirect, self.process, 'Tag/name/yo/edit') |
|
111 |
self.assertRaises(Redirect, self.process, 'Tag/yo/edit') |
|
112 |
self.assertRaises(NotFound, self.process, 'view/edit') |
|
113 |
self.assertRaises(NotFound, self.process, '1/non_action') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
114 |
self.assertRaises(NotFound, self.process, 'CWUser/login/admin/non_action') |
0 | 115 |
|
116 |
||
117 |
def test_regexp_path(self): |
|
118 |
"""tests the regexp path resolution""" |
|
119 |
ctrl, rset = self.process('add/Task') |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
120 |
self.assertEqual(ctrl, 'view') |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
121 |
self.assertEqual(rset, None) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
122 |
self.assertEqual(self.req.form, {'etype' : "Task", 'vid' : "creation"}) |
0 | 123 |
self.assertRaises(NotFound, self.process, 'add/foo/bar') |
124 |
||
125 |
||
126 |
def test_nonascii_path(self): |
|
127 |
oldrules = SimpleReqRewriter.rules |
|
128 |
SimpleReqRewriter.rules = [(re.compile('/\w+', re.U), dict(vid='foo')),] |
|
129 |
try: |
|
130 |
path = str(FakeRequest().url_quote(u'été')) |
|
131 |
ctrl, rset = self.process(path) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
132 |
self.assertEqual(rset, None) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6315
diff
changeset
|
133 |
self.assertEqual(self.req.form, {'vid' : "foo"}) |
0 | 134 |
finally: |
135 |
SimpleReqRewriter.rules = oldrules |
|
1654 | 136 |
|
0 | 137 |
|
138 |
if __name__ == '__main__': |
|
139 |
unittest_main() |