ext/test/unittest_rest.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 03 Apr 2014 19:55:19 +0200
changeset 9657 3ff4c6f80c37
parent 9517 3338b2205ea3
child 9856 156a3fb4a884
permissions -rw-r--r--
[test] update unittest_utils to 3.19 api
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
     1
# copyright 2003-2013 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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
1643
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    21
from cubicweb.ext.rest import rest_publish
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    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
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    26
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    27
    def test_eid_role(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    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
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    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
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    32
                          '<p><a class="reference" href="http://testing.fr/cubicweb/cwuser/admin">some text</a></p>\n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    34
    def test_bad_rest_no_crash(self):
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    35
        data = rest_publish(self.context(), '''
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    36
| card | implication     |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
--------------------------
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    38
| 1-1  | N1 = N2         |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
| 1-?  | N1 <= N2        |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
| 1-+  | N1 >= N2        |
1643
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    41
| 1-*  | N1>0 => N2>0    |
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    42
--------------------------
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
| ?-?  | N1 # N2         |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
| ?-+  | N1 >= N2        |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
| ?-*  | N1 #  N2        |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
--------------------------
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
| +-+  | N1>0 => N2>0 et |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    48
|      | N2>0 => N1>0    |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
| +-*  | N1>+ => N2>0    |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
--------------------------
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    51
| *-*  | N1#N2           |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    52
--------------------------
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    53
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    54
''')
1643
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    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`')
9517
3338b2205ea3 Typo in comments and error messages
Dimitri Papadopoulos <dimitri.papadopoulos@cea.fr>
parents: 9322
diff changeset
    71
        self.assertTrue(out.startswith("<p>an error occurred 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
8852
59a29405688c [ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8255
diff changeset
    78
    def test_bookmark_role(self):
59a29405688c [ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8255
diff changeset
    79
        context = self.context()
59a29405688c [ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8255
diff changeset
    80
        rset = self.execute('INSERT Bookmark X: X title "hello", X path "/view?rql=Any X WHERE X is CWUser"')
59a29405688c [ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8255
diff changeset
    81
        eid = rset[0][0]
59a29405688c [ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8255
diff changeset
    82
        out = rest_publish(context, ':bookmark:`%s`' % eid)
59a29405688c [ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8255
diff changeset
    83
        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')
59a29405688c [ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8255
diff changeset
    84
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    85
    def test_rqltable_nocontent(self):
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    86
        context = self.context()
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    87
        out = rest_publish(context, """.. rql-table::""")
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    88
        self.assertIn("System Message: ERROR", out)
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    89
        self.assertIn("Content block expected for the &quot;rql-table&quot; "
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    90
                      "directive; none found" , out)
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    91
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    92
    def test_rqltable_norset(self):
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    93
        context = self.context()
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    94
        rql = "Any X WHERE X is CWUser, X firstname 'franky'"
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    95
        out = rest_publish(
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    96
            context, """\
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    97
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    98
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
    99
            %(rql)s""" % {'rql': rql})
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   100
        self.assertIn("System Message: WARNING", out)
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   101
        self.assertIn("empty result set", out)
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   102
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   103
    def test_rqltable_nooptions(self):
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   104
        rql = """Any S,F,L WHERE X is CWUser, X surname S,
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   105
                                 X firstname F, X login L"""
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   106
        out = rest_publish(
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   107
            self.context(), """\
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   108
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   109
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   110
   %(rql)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   111
            """ % {'rql': rql})
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   112
        req = self.request()
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   113
        view = self.vreg['views'].select('table', req, rset=req.execute(rql))
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   114
        self.assertEqual(view.render(w=None)[49:], out[49:])
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   115
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   116
    def test_rqltable_vid(self):
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   117
        rql = """Any S,F,L WHERE X is CWUser, X surname S,
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   118
                                 X firstname F, X login L"""
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   119
        vid = 'mytable'
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   120
        out = rest_publish(
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   121
            self.context(), """\
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   122
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   123
   :vid: %(vid)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   124
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   125
   %(rql)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   126
            """ % {'rql': rql, 'vid': vid})
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   127
        req = self.request()
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   128
        view = self.vreg['views'].select(vid, req, rset=req.execute(rql))
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   129
        self.assertEqual(view.render(w=None)[49:], out[49:])
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   130
        self.assertIn(vid, out[:49])
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   131
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   132
    def test_rqltable_badvid(self):
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   133
        rql = """Any S,F,L WHERE X is CWUser, X surname S,
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   134
                                 X firstname F, X login L"""
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   135
        vid = 'mytabel'
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   136
        out = rest_publish(
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   137
            self.context(), """\
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   138
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   139
   :vid: %(vid)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   140
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   141
   %(rql)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   142
            """ % {'rql': rql, 'vid': vid})
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   143
        self.assertIn("fail to select '%s' view" % vid, out)
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   144
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   145
    def test_rqltable_headers(self):
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   146
        rql = """Any S,F,L WHERE X is CWUser, X surname S,
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   147
                                 X firstname F, X login L"""
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   148
        headers = ["nom", "prenom", "identifiant"]
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   149
        out = rest_publish(
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   150
            self.context(), """\
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   151
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   152
   :headers: %(headers)s
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
   %(rql)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   155
            """ % {'rql': rql, 'headers': ', '.join(headers)})
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   156
        req = self.request()
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   157
        view = self.vreg['views'].select('table', req, rset=req.execute(rql))
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   158
        view.headers = headers
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   159
        self.assertEqual(view.render(w=None)[49:], out[49:])
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   160
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   161
    def test_rqltable_headers_missing(self):
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   162
        rql = """Any S,F,L WHERE X is CWUser, X surname S,
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   163
                                 X firstname F, X login L"""
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   164
        headers = ["nom", "", "identifiant"]
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   165
        out = rest_publish(
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   166
            self.context(), """\
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   167
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   168
   :headers: %(headers)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   169
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   170
   %(rql)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   171
            """ % {'rql': rql, 'headers': ', '.join(headers)})
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   172
        req = self.request()
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   173
        view = self.vreg['views'].select('table', req, rset=req.execute(rql))
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   174
        view.headers = [headers[0], None, headers[2]]
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   175
        self.assertEqual(view.render(w=None)[49:], out[49:])
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   176
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   177
    def test_rqltable_headers_missing_edges(self):
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   178
        rql = """Any S,F,L WHERE X is CWUser, X surname S,
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   179
                                 X firstname F, X login L"""
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   180
        headers = [" ", "prenom", ""]
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   181
        out = rest_publish(
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   182
            self.context(), """\
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   183
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   184
   :headers: %(headers)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   185
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   186
   %(rql)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   187
            """ % {'rql': rql, 'headers': ', '.join(headers)})
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   188
        req = self.request()
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   189
        view = self.vreg['views'].select('table', req, rset=req.execute(rql))
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   190
        view.headers = [None, headers[1], None]
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   191
        self.assertEqual(view.render(w=None)[49:], out[49:])
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   192
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   193
    def test_rqltable_colvids(self):
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   194
        rql = """Any X,S,F,L WHERE X is CWUser, X surname S,
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   195
                                   X firstname F, X login L"""
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   196
        colvids = {0: "oneline"}
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   197
        out = rest_publish(
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   198
            self.context(), """\
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   199
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   200
   :colvids: %(colvids)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   201
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   202
   %(rql)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   203
            """ % {'rql': rql,
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   204
                   'colvids': ', '.join(["%d=%s" % (k, v)
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   205
                                         for k, v in colvids.iteritems()])
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   206
                  })
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   207
        req = self.request()
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   208
        view = self.vreg['views'].select('table', req, rset=req.execute(rql))
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   209
        view.cellvids = colvids
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   210
        self.assertEqual(view.render(w=None)[49:], out[49:])
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
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   213
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   214
    unittest_main()