author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 20 Jan 2010 10:13:45 +0100 | |
changeset 4281 | 74c1597f8a82 |
parent 4252 | 6c4f109c2b03 |
child 5174 | 78438ad513ca |
child 5421 | 8167de96c523 |
permissions | -rw-r--r-- |
0 | 1 |
# -*- coding: utf-8 -*- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
2 |
"""Unit tests for url publishing service |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
3 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
4 |
:organization: Logilab |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
5 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
6 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
7 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
8 |
""" |
0 | 9 |
|
10 |
import re |
|
11 |
||
12 |
from logilab.common.testlib import unittest_main |
|
13 |
||
14 |
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
|
15 |
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
|
16 |
from cubicweb.devtools.fake import FakeRequest |
0 | 17 |
from cubicweb.web import NotFound, Redirect |
18 |
from cubicweb.web.views.urlrewrite import SimpleReqRewriter |
|
19 |
||
20 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
21 |
class URLPublisherTC(CubicWebTC): |
0 | 22 |
"""test suite for QSPreProcessor""" |
23 |
||
24 |
def setup_database(self): |
|
25 |
self.create_user(u'ÿsaÿe') |
|
4172
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
26 |
req = self.request() |
4d4cef034eec
all web tests OK
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
2773
diff
changeset
|
27 |
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
|
28 |
c = req.create_entity('Tag', name=u'yo') # take care: Tag's name normalized to lower case |
0 | 29 |
self.execute('SET C tags B WHERE C eid %(c)s, B eid %(b)s', {'c':c.eid, 'b':b.eid}, 'b') |
1654 | 30 |
|
0 | 31 |
def process(self, url): |
32 |
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
|
33 |
return self.app.url_resolver.process(req, url) |
1654 | 34 |
|
0 | 35 |
def test_raw_path(self): |
36 |
"""tests raw path resolution'""" |
|
37 |
self.assertEquals(self.process('view'), ('view', None)) |
|
38 |
self.assertEquals(self.process('edit'), ('edit', None)) |
|
39 |
self.assertRaises(NotFound, self.process, 'whatever') |
|
40 |
||
41 |
def test_eid_path(self): |
|
42 |
"""tests eid path resolution""" |
|
43 |
self.assertIsInstance(self.process('123')[1], ResultSet) |
|
44 |
self.assertEquals(len(self.process('123')[1]), 1) |
|
45 |
self.assertRaises(NotFound, self.process, '123/345') |
|
46 |
self.assertRaises(NotFound, self.process, 'not_eid') |
|
47 |
||
48 |
def test_rest_path(self): |
|
49 |
"""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
|
50 |
ctrl, rset = self.process('CWUser') |
0 | 51 |
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
|
52 |
self.assertEquals(rset.description[0][0], 'CWUser') |
0 | 53 |
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
|
54 |
"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
|
55 |
ctrl, rset = self.process('CWUser/login/admin') |
0 | 56 |
self.assertEquals(ctrl, 'view') |
57 |
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
|
58 |
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
|
59 |
self.assertEquals(rset.printable_rql(), 'Any X WHERE X is CWUser, X login "admin"') |
1654 | 60 |
ctrl, rset = self.process('cwuser/admin') |
0 | 61 |
self.assertEquals(ctrl, 'view') |
62 |
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
|
63 |
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
|
64 |
self.assertEquals(rset.printable_rql(), 'Any X WHERE X is CWUser, X login "admin"') |
1654 | 65 |
ctrl, rset = self.process('cwuser/eid/%s'%rset[0][0]) |
0 | 66 |
self.assertEquals(ctrl, 'view') |
67 |
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
|
68 |
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
|
69 |
self.assertEquals(rset.printable_rql(), 'Any X WHERE X is CWUser, X eid 5') |
0 | 70 |
# 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
|
71 |
ctrl, rset = self.process('CWUser/login/%C3%BFsa%C3%BFe') |
0 | 72 |
self.assertEquals(ctrl, 'view') |
73 |
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
|
74 |
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
|
75 |
self.assertEquals(rset.printable_rql(), u'Any X WHERE X is CWUser, X login "ÿsaÿe"') |
0 | 76 |
# test quoted paths |
77 |
ctrl, rset = self.process('BlogEntry/title/hell%27o') |
|
78 |
self.assertEquals(ctrl, 'view') |
|
79 |
self.assertEquals(len(rset), 1) |
|
80 |
self.assertEquals(rset.description[0][0], 'BlogEntry') |
|
81 |
self.assertEquals(rset.printable_rql(), u'Any X WHERE X is BlogEntry, X title "hell\'o"') |
|
82 |
# errors |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
83 |
self.assertRaises(NotFound, self.process, 'CWUser/eid/30000') |
0 | 84 |
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
|
85 |
self.assertRaises(NotFound, self.process, 'CWUser/inexistant_attribute/joe') |
1654 | 86 |
|
0 | 87 |
def test_action_path(self): |
88 |
"""tests the action path resolution""" |
|
89 |
self.assertRaises(Redirect, self.process, '1/edit') |
|
90 |
self.assertRaises(Redirect, self.process, 'Tag/name/yo/edit') |
|
91 |
self.assertRaises(Redirect, self.process, 'Tag/yo/edit') |
|
92 |
self.assertRaises(NotFound, self.process, 'view/edit') |
|
93 |
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
|
94 |
self.assertRaises(NotFound, self.process, 'CWUser/login/admin/non_action') |
0 | 95 |
|
96 |
||
97 |
def test_regexp_path(self): |
|
98 |
"""tests the regexp path resolution""" |
|
99 |
ctrl, rset = self.process('add/Task') |
|
100 |
self.assertEquals(ctrl, 'view') |
|
1654 | 101 |
self.assertEquals(rset, None) |
0 | 102 |
self.assertEquals(self.req.form, {'etype' : "Task", 'vid' : "creation"}) |
103 |
self.assertRaises(NotFound, self.process, 'add/foo/bar') |
|
104 |
||
105 |
||
106 |
def test_nonascii_path(self): |
|
107 |
oldrules = SimpleReqRewriter.rules |
|
108 |
SimpleReqRewriter.rules = [(re.compile('/\w+', re.U), dict(vid='foo')),] |
|
109 |
try: |
|
110 |
path = str(FakeRequest().url_quote(u'été')) |
|
111 |
ctrl, rset = self.process(path) |
|
1654 | 112 |
self.assertEquals(rset, None) |
0 | 113 |
self.assertEquals(self.req.form, {'vid' : "foo"}) |
114 |
finally: |
|
115 |
SimpleReqRewriter.rules = oldrules |
|
1654 | 116 |
|
0 | 117 |
|
118 |
if __name__ == '__main__': |
|
119 |
unittest_main() |