author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 12 Aug 2010 10:11:49 +0200 | |
branch | stable |
changeset 6101 | 1aff7367a20c |
parent 5426 | 0d4853a6e5ee |
child 6315 | 8ca3ee849bee |
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/>. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
19 |
"""Unit tests for url publishing service |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
20 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
21 |
""" |
0 | 22 |
|
23 |
import re |
|
24 |
||
25 |
from logilab.common.testlib import unittest_main |
|
26 |
||
27 |
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
|
28 |
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
|
29 |
from cubicweb.devtools.fake import FakeRequest |
0 | 30 |
from cubicweb.web import NotFound, Redirect |
31 |
from cubicweb.web.views.urlrewrite import SimpleReqRewriter |
|
32 |
||
33 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
34 |
class URLPublisherTC(CubicWebTC): |
0 | 35 |
"""test suite for QSPreProcessor""" |
36 |
||
37 |
def setup_database(self): |
|
38 |
self.create_user(u'ÿsaÿe') |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
39 |
req = self.request() |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
40 |
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
|
41 |
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
|
42 |
self.execute('SET C tags B WHERE C eid %(c)s, B eid %(b)s', {'c':c.eid, 'b':b.eid}) |
1654 | 43 |
|
0 | 44 |
def process(self, url): |
45 |
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
|
46 |
return self.app.url_resolver.process(req, url) |
1654 | 47 |
|
0 | 48 |
def test_raw_path(self): |
49 |
"""tests raw path resolution'""" |
|
50 |
self.assertEquals(self.process('view'), ('view', None)) |
|
51 |
self.assertEquals(self.process('edit'), ('edit', None)) |
|
52 |
self.assertRaises(NotFound, self.process, 'whatever') |
|
53 |
||
54 |
def test_eid_path(self): |
|
55 |
"""tests eid path resolution""" |
|
56 |
self.assertIsInstance(self.process('123')[1], ResultSet) |
|
57 |
self.assertEquals(len(self.process('123')[1]), 1) |
|
58 |
self.assertRaises(NotFound, self.process, '123/345') |
|
59 |
self.assertRaises(NotFound, self.process, 'not_eid') |
|
60 |
||
61 |
def test_rest_path(self): |
|
62 |
"""tests the rest path resolution""" |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
63 |
ctrl, rset = self.process('CWUser') |
0 | 64 |
self.assertEquals(ctrl, 'view') |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
65 |
self.assertEquals(rset.description[0][0], 'CWUser') |
0 | 66 |
self.assertEquals(rset.printable_rql(), |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
67 |
"Any X,AA,AB,AC,AD ORDERBY AA WHERE X is CWUser, X login AA, X firstname AB, X surname AC, X modification_date AD") |
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') |
0 | 69 |
self.assertEquals(ctrl, 'view') |
70 |
self.assertEquals(len(rset), 1) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
71 |
self.assertEquals(rset.description[0][0], 'CWUser') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
72 |
self.assertEquals(rset.printable_rql(), 'Any X WHERE X is CWUser, X login "admin"') |
1654 | 73 |
ctrl, rset = self.process('cwuser/admin') |
0 | 74 |
self.assertEquals(ctrl, 'view') |
75 |
self.assertEquals(len(rset), 1) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
76 |
self.assertEquals(rset.description[0][0], 'CWUser') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
77 |
self.assertEquals(rset.printable_rql(), 'Any X WHERE X is CWUser, X login "admin"') |
1654 | 78 |
ctrl, rset = self.process('cwuser/eid/%s'%rset[0][0]) |
0 | 79 |
self.assertEquals(ctrl, 'view') |
80 |
self.assertEquals(len(rset), 1) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
81 |
self.assertEquals(rset.description[0][0], 'CWUser') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
82 |
self.assertEquals(rset.printable_rql(), 'Any X WHERE X is CWUser, X eid 5') |
0 | 83 |
# test non-ascii paths |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
84 |
ctrl, rset = self.process('CWUser/login/%C3%BFsa%C3%BFe') |
0 | 85 |
self.assertEquals(ctrl, 'view') |
86 |
self.assertEquals(len(rset), 1) |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
87 |
self.assertEquals(rset.description[0][0], 'CWUser') |
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
88 |
self.assertEquals(rset.printable_rql(), u'Any X WHERE X is CWUser, X login "ÿsaÿe"') |
0 | 89 |
# test quoted paths |
90 |
ctrl, rset = self.process('BlogEntry/title/hell%27o') |
|
91 |
self.assertEquals(ctrl, 'view') |
|
92 |
self.assertEquals(len(rset), 1) |
|
93 |
self.assertEquals(rset.description[0][0], 'BlogEntry') |
|
94 |
self.assertEquals(rset.printable_rql(), u'Any X WHERE X is BlogEntry, X title "hell\'o"') |
|
95 |
# errors |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
96 |
self.assertRaises(NotFound, self.process, 'CWUser/eid/30000') |
0 | 97 |
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
|
98 |
self.assertRaises(NotFound, self.process, 'CWUser/inexistant_attribute/joe') |
1654 | 99 |
|
0 | 100 |
def test_action_path(self): |
101 |
"""tests the action path resolution""" |
|
102 |
self.assertRaises(Redirect, self.process, '1/edit') |
|
103 |
self.assertRaises(Redirect, self.process, 'Tag/name/yo/edit') |
|
104 |
self.assertRaises(Redirect, self.process, 'Tag/yo/edit') |
|
105 |
self.assertRaises(NotFound, self.process, 'view/edit') |
|
106 |
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
|
107 |
self.assertRaises(NotFound, self.process, 'CWUser/login/admin/non_action') |
0 | 108 |
|
109 |
||
110 |
def test_regexp_path(self): |
|
111 |
"""tests the regexp path resolution""" |
|
112 |
ctrl, rset = self.process('add/Task') |
|
113 |
self.assertEquals(ctrl, 'view') |
|
1654 | 114 |
self.assertEquals(rset, None) |
0 | 115 |
self.assertEquals(self.req.form, {'etype' : "Task", 'vid' : "creation"}) |
116 |
self.assertRaises(NotFound, self.process, 'add/foo/bar') |
|
117 |
||
118 |
||
119 |
def test_nonascii_path(self): |
|
120 |
oldrules = SimpleReqRewriter.rules |
|
121 |
SimpleReqRewriter.rules = [(re.compile('/\w+', re.U), dict(vid='foo')),] |
|
122 |
try: |
|
123 |
path = str(FakeRequest().url_quote(u'été')) |
|
124 |
ctrl, rset = self.process(path) |
|
1654 | 125 |
self.assertEquals(rset, None) |
0 | 126 |
self.assertEquals(self.req.form, {'vid' : "foo"}) |
127 |
finally: |
|
128 |
SimpleReqRewriter.rules = oldrules |
|
1654 | 129 |
|
0 | 130 |
|
131 |
if __name__ == '__main__': |
|
132 |
unittest_main() |