author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 11 Jun 2014 14:47:50 +0200 | |
changeset 10361 | 46d72f33c428 |
parent 9856 | 156a3fb4a884 |
child 10662 | 10942ed172de |
child 10952 | 4f28cb25b6c1 |
permissions | -rw-r--r-- |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
1 |
# 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
|
2 |
# 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
|
3 |
# |
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 |
# 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
|
5 |
# |
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 |
# 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
|
7 |
# 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
|
8 |
# 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
|
9 |
# 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
|
10 |
# |
5424
8ecbcbff9777
replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5421
diff
changeset
|
11 |
# 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
|
12 |
# 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
|
13 |
# 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
|
14 |
# 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
|
15 |
# |
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 |
# 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
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
from logilab.common.testlib import unittest_main |
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
19 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 20 |
|
1643 | 21 |
from cubicweb.ext.rest import rest_publish |
22 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
23 |
class RestTC(CubicWebTC): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
24 |
|
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
25 |
def context(self, req): |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
26 |
return req.execute('CWUser X WHERE X login "admin"').get_entity(0, 0) |
1643 | 27 |
|
0 | 28 |
def test_eid_role(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
29 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
30 |
context = self.context(req) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
31 |
self.assertEqual(rest_publish(context, ':eid:`%s`' % context.eid), |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
32 |
'<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
33 |
'#%s</a></p>\n' % context.eid) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
34 |
self.assertEqual(rest_publish(context, ':eid:`%s:some text`' % context.eid), |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
35 |
'<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
36 |
'some text</a></p>\n') |
0 | 37 |
|
38 |
def test_bad_rest_no_crash(self): |
|
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
39 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
40 |
rest_publish(self.context(req), ''' |
0 | 41 |
| card | implication | |
42 |
-------------------------- |
|
43 |
| 1-1 | N1 = N2 | |
|
44 |
| 1-? | N1 <= N2 | |
|
45 |
| 1-+ | N1 >= N2 | |
|
1643 | 46 |
| 1-* | N1>0 => N2>0 | |
0 | 47 |
-------------------------- |
48 |
| ?-? | N1 # N2 | |
|
49 |
| ?-+ | N1 >= N2 | |
|
50 |
| ?-* | N1 # N2 | |
|
51 |
-------------------------- |
|
52 |
| +-+ | N1>0 => N2>0 et | |
|
53 |
| | N2>0 => N1>0 | |
|
54 |
| +-* | N1>+ => N2>0 | |
|
55 |
-------------------------- |
|
56 |
| *-* | N1#N2 | |
|
57 |
-------------------------- |
|
58 |
||
59 |
''') |
|
1643 | 60 |
|
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
61 |
|
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
62 |
def test_rql_role_with_vid(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
63 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
64 |
context = self.context(req) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
65 |
out = rest_publish(context, ':rql:`Any X WHERE X is CWUser:table`') |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
66 |
self.assertTrue(out.endswith('<a href="http://testing.fr/cubicweb/cwuser/anon" ' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
67 |
'title="">anon</a></td></tr>\n</tbody></table>' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
68 |
'</div></p>\n')) |
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
69 |
|
7732
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
70 |
def test_rql_role_with_vid_empty_rset(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
71 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
72 |
context = self.context(req) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
73 |
out = rest_publish(context, ':rql:`Any X WHERE X is CWUser, X login "nono":table`') |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
74 |
self.assertTrue(out.endswith('<p><div class="searchMessage"><strong>' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
75 |
'No result matching query</strong></div>\n</p>\n')) |
7732
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
76 |
|
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
77 |
def test_rql_role_with_unknown_vid(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
78 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
79 |
context = self.context(req) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
80 |
out = rest_publish(context, ':rql:`Any X WHERE X is CWUser:toto`') |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
81 |
self.assertTrue(out.startswith("<p>an error occurred while interpreting this " |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
82 |
"rql directive: ObjectNotFound(u'toto',)</p>")) |
7732
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
83 |
|
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
84 |
def test_rql_role_without_vid(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
85 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
86 |
context = self.context(req) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
87 |
out = rest_publish(context, ':rql:`Any X WHERE X is CWUser`') |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
88 |
self.assertEqual(out, u'<p><h1>CWUser_plural</h1><div class="section">' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
89 |
'<a href="http://testing.fr/cubicweb/cwuser/admin" title="">admin</a>' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
90 |
'</div><div class="section">' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
91 |
'<a href="http://testing.fr/cubicweb/cwuser/anon" title="">anon</a>' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
92 |
'</div></p>\n') |
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
93 |
|
8852
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8255
diff
changeset
|
94 |
def test_bookmark_role(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
95 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
96 |
context = self.context(req) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
97 |
rset = req.execute('INSERT Bookmark X: X title "hello", X path ' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
98 |
'"/view?rql=Any X WHERE X is CWUser"') |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
99 |
eid = rset[0][0] |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
100 |
out = rest_publish(context, ':bookmark:`%s`' % eid) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
101 |
self.assertEqual(out, u'<p><h1>CWUser_plural</h1><div class="section">' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
102 |
'<a href="http://testing.fr/cubicweb/cwuser/admin" title="">admin' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
103 |
'</a></div><div class="section">' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
104 |
'<a href="http://testing.fr/cubicweb/cwuser/anon" title="">anon' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
105 |
'</a></div></p>\n') |
8852
59a29405688c
[ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
8255
diff
changeset
|
106 |
|
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
107 |
def test_rqltable_nocontent(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
108 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
109 |
context = self.context(req) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
110 |
out = rest_publish(context, """.. rql-table::""") |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
111 |
self.assertIn("System Message: ERROR", out) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
112 |
self.assertIn("Content block expected for the "rql-table" " |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
113 |
"directive; none found" , out) |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
114 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
115 |
def test_rqltable_norset(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
116 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
117 |
context = self.context(req) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
118 |
rql = "Any X WHERE X is CWUser, X firstname 'franky'" |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
119 |
out = rest_publish( |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
120 |
context, """\ |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
121 |
.. rql-table:: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
122 |
|
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
123 |
%(rql)s""" % {'rql': rql}) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
124 |
self.assertIn("System Message: WARNING", out) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
125 |
self.assertIn("empty result set", out) |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
126 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
127 |
def test_rqltable_nooptions(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
128 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
129 |
rql = "Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L" |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
130 |
out = rest_publish( |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
131 |
self.context(req), """\ |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
132 |
.. rql-table:: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
133 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
134 |
%(rql)s |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
135 |
""" % {'rql': rql}) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
136 |
view = self.vreg['views'].select('table', req, rset=req.execute(rql)) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
137 |
self.assertEqual(view.render(w=None)[49:], out[49:]) |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
138 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
139 |
def test_rqltable_vid(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
140 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
141 |
rql = "Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L" |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
142 |
vid = 'mytable' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
143 |
out = rest_publish( |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
144 |
self.context(req), """\ |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
145 |
.. rql-table:: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
146 |
:vid: %(vid)s |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
147 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
148 |
%(rql)s |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
149 |
""" % {'rql': rql, 'vid': vid}) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
150 |
view = self.vreg['views'].select(vid, req, rset=req.execute(rql)) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
151 |
self.assertEqual(view.render(w=None)[49:], out[49:]) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
152 |
self.assertIn(vid, out[:49]) |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
153 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
154 |
def test_rqltable_badvid(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
155 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
156 |
rql = "Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L" |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
157 |
vid = 'mytabel' |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
158 |
out = rest_publish( |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
159 |
self.context(req), """\ |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
160 |
.. rql-table:: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
161 |
:vid: %(vid)s |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
162 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
163 |
%(rql)s |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
164 |
""" % {'rql': rql, 'vid': vid}) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
165 |
self.assertIn("fail to select '%s' view" % vid, out) |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
166 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
167 |
def test_rqltable_headers(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
168 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
169 |
rql = "Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L" |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
170 |
headers = ["nom", "prenom", "identifiant"] |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
171 |
out = rest_publish( |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
172 |
self.context(req), """\ |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
173 |
.. rql-table:: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
174 |
:headers: %(headers)s |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
175 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
176 |
%(rql)s |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
177 |
""" % {'rql': rql, 'headers': ', '.join(headers)}) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
178 |
view = self.vreg['views'].select('table', req, rset=req.execute(rql)) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
179 |
view.headers = headers |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
180 |
self.assertEqual(view.render(w=None)[49:], out[49:]) |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
181 |
|
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
182 |
def test_rqltable_headers_missing(self): |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
183 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
184 |
rql = "Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L" |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
185 |
headers = ["nom", "", "identifiant"] |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
186 |
out = rest_publish( |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
187 |
self.context(req), """\ |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
188 |
.. rql-table:: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
189 |
:headers: %(headers)s |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
190 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
191 |
%(rql)s |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
192 |
""" % {'rql': rql, 'headers': ', '.join(headers)}) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
193 |
view = self.vreg['views'].select('table', req, rset=req.execute(rql)) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
194 |
view.headers = [headers[0], None, headers[2]] |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
195 |
self.assertEqual(view.render(w=None)[49:], out[49:]) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
196 |
|
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
197 |
def test_rqltable_headers_missing_edges(self): |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
198 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
199 |
rql = "Any S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L" |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
200 |
headers = [" ", "prenom", ""] |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
201 |
out = rest_publish( |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
202 |
self.context(req), """\ |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
203 |
.. rql-table:: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
204 |
:headers: %(headers)s |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
205 |
|
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
206 |
%(rql)s |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
207 |
""" % {'rql': rql, 'headers': ', '.join(headers)}) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
208 |
view = self.vreg['views'].select('table', req, rset=req.execute(rql)) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
209 |
view.headers = [None, headers[1], None] |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
210 |
self.assertEqual(view.render(w=None)[49:], out[49:]) |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
211 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
212 |
def test_rqltable_colvids(self): |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
213 |
with self.admin_access.web_request() as req: |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
214 |
rql = "Any X,S,F,L WHERE X is CWUser, X surname S, X firstname F, X login L" |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
215 |
colvids = {0: "oneline"} |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
216 |
out = rest_publish( |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
217 |
self.context(req), """\ |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
218 |
.. rql-table:: |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
219 |
:colvids: %(colvids)s |
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
220 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
221 |
%(rql)s |
9856
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
222 |
""" % {'rql': rql, |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
223 |
'colvids': ', '.join(["%d=%s" % (k, v) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
224 |
for k, v in colvids.iteritems()]) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
225 |
}) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
226 |
view = self.vreg['views'].select('table', req, rset=req.execute(rql)) |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
227 |
view.cellvids = colvids |
156a3fb4a884
[exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
9517
diff
changeset
|
228 |
self.assertEqual(view.render(w=None)[49:], out[49:]) |
9322
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
229 |
|
2dae5bf5ea68
[ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents:
8852
diff
changeset
|
230 |
|
0 | 231 |
if __name__ == '__main__': |
232 |
unittest_main() |