author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 23 Sep 2009 19:23:09 +0200 | |
changeset 3447 | 0a0f8df4a2f7 |
parent 2773 | b2530e3e0afb |
child 4172 | 4d4cef034eec |
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 |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1654
diff
changeset
|
5 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
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') |
|
26 |
b = self.add_entity('BlogEntry', title=u'hell\'o', content=u'blabla') |
|
27 |
c = self.add_entity('Tag', name=u'yo') # take care: Tag's name normalized to lower case |
|
28 |
self.execute('SET C tags B WHERE C eid %(c)s, B eid %(b)s', {'c':c.eid, 'b':b.eid}, 'b') |
|
1654 | 29 |
|
0 | 30 |
def process(self, url): |
31 |
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
|
32 |
return self.app.url_resolver.process(req, url) |
1654 | 33 |
|
0 | 34 |
def test_raw_path(self): |
35 |
"""tests raw path resolution'""" |
|
36 |
self.assertEquals(self.process('view'), ('view', None)) |
|
37 |
self.assertEquals(self.process('edit'), ('edit', None)) |
|
38 |
self.assertRaises(NotFound, self.process, 'whatever') |
|
39 |
||
40 |
def test_eid_path(self): |
|
41 |
"""tests eid path resolution""" |
|
42 |
self.assertIsInstance(self.process('123')[1], ResultSet) |
|
43 |
self.assertEquals(len(self.process('123')[1]), 1) |
|
44 |
self.assertRaises(NotFound, self.process, '123/345') |
|
45 |
self.assertRaises(NotFound, self.process, 'not_eid') |
|
46 |
||
47 |
def test_rest_path(self): |
|
48 |
"""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
|
49 |
ctrl, rset = self.process('CWUser') |
0 | 50 |
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
|
51 |
self.assertEquals(rset.description[0][0], 'CWUser') |
0 | 52 |
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
|
53 |
"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
|
54 |
ctrl, rset = self.process('CWUser/login/admin') |
0 | 55 |
self.assertEquals(ctrl, 'view') |
56 |
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
|
57 |
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
|
58 |
self.assertEquals(rset.printable_rql(), 'Any X WHERE X is CWUser, X login "admin"') |
1654 | 59 |
ctrl, rset = self.process('cwuser/admin') |
0 | 60 |
self.assertEquals(ctrl, 'view') |
61 |
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
|
62 |
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
|
63 |
self.assertEquals(rset.printable_rql(), 'Any X WHERE X is CWUser, X login "admin"') |
1654 | 64 |
ctrl, rset = self.process('cwuser/eid/%s'%rset[0][0]) |
0 | 65 |
self.assertEquals(ctrl, 'view') |
66 |
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
|
67 |
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
|
68 |
self.assertEquals(rset.printable_rql(), 'Any X WHERE X is CWUser, X eid 5') |
0 | 69 |
# 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
|
70 |
ctrl, rset = self.process('CWUser/login/%C3%BFsa%C3%BFe') |
0 | 71 |
self.assertEquals(ctrl, 'view') |
72 |
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
|
73 |
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
|
74 |
self.assertEquals(rset.printable_rql(), u'Any X WHERE X is CWUser, X login "ÿsaÿe"') |
0 | 75 |
# test quoted paths |
76 |
ctrl, rset = self.process('BlogEntry/title/hell%27o') |
|
77 |
self.assertEquals(ctrl, 'view') |
|
78 |
self.assertEquals(len(rset), 1) |
|
79 |
self.assertEquals(rset.description[0][0], 'BlogEntry') |
|
80 |
self.assertEquals(rset.printable_rql(), u'Any X WHERE X is BlogEntry, X title "hell\'o"') |
|
81 |
# errors |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
82 |
self.assertRaises(NotFound, self.process, 'CWUser/eid/30000') |
0 | 83 |
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
|
84 |
self.assertRaises(NotFound, self.process, 'CWUser/inexistant_attribute/joe') |
1654 | 85 |
|
0 | 86 |
def test_action_path(self): |
87 |
"""tests the action path resolution""" |
|
88 |
self.assertRaises(Redirect, self.process, '1/edit') |
|
89 |
self.assertRaises(Redirect, self.process, 'Tag/name/yo/edit') |
|
90 |
self.assertRaises(Redirect, self.process, 'Tag/yo/edit') |
|
91 |
self.assertRaises(NotFound, self.process, 'view/edit') |
|
92 |
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
|
93 |
self.assertRaises(NotFound, self.process, 'CWUser/login/admin/non_action') |
0 | 94 |
|
95 |
||
96 |
def test_regexp_path(self): |
|
97 |
"""tests the regexp path resolution""" |
|
98 |
ctrl, rset = self.process('add/Task') |
|
99 |
self.assertEquals(ctrl, 'view') |
|
1654 | 100 |
self.assertEquals(rset, None) |
0 | 101 |
self.assertEquals(self.req.form, {'etype' : "Task", 'vid' : "creation"}) |
102 |
self.assertRaises(NotFound, self.process, 'add/foo/bar') |
|
103 |
||
104 |
||
105 |
def test_nonascii_path(self): |
|
106 |
oldrules = SimpleReqRewriter.rules |
|
107 |
SimpleReqRewriter.rules = [(re.compile('/\w+', re.U), dict(vid='foo')),] |
|
108 |
try: |
|
109 |
path = str(FakeRequest().url_quote(u'été')) |
|
110 |
ctrl, rset = self.process(path) |
|
1654 | 111 |
self.assertEquals(rset, None) |
0 | 112 |
self.assertEquals(self.req.form, {'vid' : "foo"}) |
113 |
finally: |
|
114 |
SimpleReqRewriter.rules = oldrules |
|
1654 | 115 |
|
0 | 116 |
|
117 |
if __name__ == '__main__': |
|
118 |
unittest_main() |