author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Mon, 04 Feb 2013 14:39:55 +0100 | |
branch | oldstable |
changeset 8858 | 51fdbbbd07b2 |
parent 8255 | 25a00e4a8722 |
child 8852 | 59a29405688c |
permissions | -rw-r--r-- |
8255
25a00e4a8722
[test] fix ReST extensions tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7732
diff
changeset
|
1 |
# copyright 2003-2012 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): |
0 | 24 |
def context(self): |
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
25 |
return self.execute('CWUser X WHERE X login "admin"').get_entity(0, 0) |
1643 | 26 |
|
0 | 27 |
def test_eid_role(self): |
28 |
context = self.context() |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
29 |
self.assertEqual(rest_publish(context, ':eid:`%s`' % context.eid), |
1643 | 30 |
'<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">#%s</a></p>\n' % context.eid) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
31 |
self.assertEqual(rest_publish(context, ':eid:`%s:some text`' % context.eid), |
1643 | 32 |
'<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">some text</a></p>\n') |
0 | 33 |
|
34 |
def test_bad_rest_no_crash(self): |
|
35 |
data = rest_publish(self.context(), ''' |
|
36 |
| card | implication | |
|
37 |
-------------------------- |
|
38 |
| 1-1 | N1 = N2 | |
|
39 |
| 1-? | N1 <= N2 | |
|
40 |
| 1-+ | N1 >= N2 | |
|
1643 | 41 |
| 1-* | N1>0 => N2>0 | |
0 | 42 |
-------------------------- |
43 |
| ?-? | N1 # N2 | |
|
44 |
| ?-+ | N1 >= N2 | |
|
45 |
| ?-* | N1 # N2 | |
|
46 |
-------------------------- |
|
47 |
| +-+ | N1>0 => N2>0 et | |
|
48 |
| | N2>0 => N1>0 | |
|
49 |
| +-* | N1>+ => N2>0 | |
|
50 |
-------------------------- |
|
51 |
| *-* | N1#N2 | |
|
52 |
-------------------------- |
|
53 |
||
54 |
''') |
|
1643 | 55 |
|
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
56 |
|
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
57 |
def test_rql_role_with_vid(self): |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
58 |
context = self.context() |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
59 |
out = rest_publish(context, ':rql:`Any X WHERE X is CWUser:table`') |
8255
25a00e4a8722
[test] fix ReST extensions tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7732
diff
changeset
|
60 |
self.assertTrue(out.endswith('<a href="http://testing.fr/cubicweb/cwuser/anon" title="">anon</a>' |
25a00e4a8722
[test] fix ReST extensions tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7732
diff
changeset
|
61 |
'</td></tr>\n</tbody></table></div></p>\n')) |
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
62 |
|
7732
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
63 |
def test_rql_role_with_vid_empty_rset(self): |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
64 |
context = self.context() |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
65 |
out = rest_publish(context, ':rql:`Any X WHERE X is CWUser, X login "nono":table`') |
8255
25a00e4a8722
[test] fix ReST extensions tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7732
diff
changeset
|
66 |
self.assertTrue(out.endswith('<p><div class="searchMessage"><strong>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
|
67 |
|
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
68 |
def test_rql_role_with_unknown_vid(self): |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
69 |
context = self.context() |
5430d0db52ab
[web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6938
diff
changeset
|
70 |
out = rest_publish(context, ':rql:`Any X WHERE X is CWUser:toto`') |
8255
25a00e4a8722
[test] fix ReST extensions tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7732
diff
changeset
|
71 |
self.assertTrue(out.startswith("<p>an error occured while interpreting this 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
|
72 |
|
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
73 |
def test_rql_role_without_vid(self): |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
74 |
context = self.context() |
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
75 |
out = rest_publish(context, ':rql:`Any X WHERE X is CWUser`') |
8255
25a00e4a8722
[test] fix ReST extensions tests
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
7732
diff
changeset
|
76 |
self.assertEqual(out, u'<p><h1>CWUser_plural</h1><div class="section"><a href="http://testing.fr/cubicweb/cwuser/admin" title="">admin</a></div><div class="section"><a href="http://testing.fr/cubicweb/cwuser/anon" title="">anon</a></div></p>\n') |
6938
6c1a960735f5
add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
6340
diff
changeset
|
77 |
|
0 | 78 |
if __name__ == '__main__': |
79 |
unittest_main() |