ext/test/unittest_rest.py
author Julien Cristau <julien.cristau@logilab.fr>
Tue, 03 Nov 2015 18:29:15 +0100
changeset 10860 252877c624f0
parent 10754 03aa9f2a4ecb
child 10960 9e64fddebc89
permissions -rw-r--r--
[dataimport/test] use the right assert methods instead of assertTrue with a comparison
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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/>.
10754
03aa9f2a4ecb [ext/test] fix test relying on repr(text)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    18
from six import PY3
03aa9f2a4ecb [ext/test] fix test relying on repr(text)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    19
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    20
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
    21
from cubicweb.devtools.testlib import CubicWebTC
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    22
1643
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    23
from cubicweb.ext.rest import rest_publish
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    24
2773
b2530e3e0afb [testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
    25
class RestTC(CubicWebTC):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    26
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    27
    def context(self, req):
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    28
        return req.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
    29
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    30
    def test_eid_role(self):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    31
        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
    32
            context = self.context(req)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    33
            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
    34
                             '<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
    35
                             '#%s</a></p>\n' % context.eid)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    36
            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
    37
                             '<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
    38
                             'some text</a></p>\n')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    39
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    40
    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
    41
        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
    42
            rest_publish(self.context(req), '''
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    43
| card | implication     |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    44
--------------------------
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    45
| 1-1  | N1 = N2         |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    46
| 1-?  | N1 <= N2        |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    47
| 1-+  | N1 >= N2        |
1643
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    48
| 1-*  | N1>0 => N2>0    |
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    49
--------------------------
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    50
| ?-?  | N1 # N2         |
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
| ?-*  | N1 #  N2        |
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
| +-+  | N1>0 => N2>0 et |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    55
|      | N2>0 => N1>0    |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    56
| +-*  | N1>+ => N2>0    |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    57
--------------------------
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    58
| *-*  | N1#N2           |
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    59
--------------------------
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    60
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    61
''')
1643
59c5cec05bbd move card role to cubes.card
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
    62
6938
6c1a960735f5 add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    63
6c1a960735f5 add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    64
    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
    65
        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
    66
            context = self.context(req)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    67
            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
    68
            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
    69
                                         '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
    70
                                         '</div></p>\n'))
6938
6c1a960735f5 add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    71
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
    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
    73
        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
    74
            context = self.context(req)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    75
            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
    76
            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
    77
                                         '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
    78
5430d0db52ab [web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6938
diff changeset
    79
    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
    80
        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
    81
            context = self.context(req)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    82
            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
    83
            self.assertTrue(out.startswith("<p>an error occurred while interpreting this "
10754
03aa9f2a4ecb [ext/test] fix test relying on repr(text)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    84
                                           "rql directive: ObjectNotFound(%s'toto',)</p>" %
03aa9f2a4ecb [ext/test] fix test relying on repr(text)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    85
                                           ('' if PY3 else 'u')),
03aa9f2a4ecb [ext/test] fix test relying on repr(text)
Julien Cristau <julien.cristau@logilab.fr>
parents: 10662
diff changeset
    86
                            out)
7732
5430d0db52ab [web] rql directive breaks if explicit vid and empty rset (closes #1893433)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6938
diff changeset
    87
6938
6c1a960735f5 add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    88
    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
    89
        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
    90
            context = self.context(req)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    91
            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
    92
            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
    93
                             '<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
    94
                             '</div><div class="section">'
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    95
                             '<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
    96
                             '</div></p>\n')
6938
6c1a960735f5 add a rql directive to restructuredtext
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 6340
diff changeset
    97
8852
59a29405688c [ext/rest] add directive bookmark to rest (closes #2545595)
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 8255
diff changeset
    98
    def test_bookmark_role(self):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
    99
        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
   100
            context = self.context(req)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   101
            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
   102
                               '"/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
   103
            eid = rset[0][0]
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   104
            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
   105
            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
   106
                             '<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
   107
                             '</a></div><div class="section">'
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   108
                             '<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
   109
                             '</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
   110
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   111
    def test_rqltable_nocontent(self):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   112
        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
   113
            context = self.context(req)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   114
            out = rest_publish(context, """.. rql-table::""")
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   115
            self.assertIn("System Message: ERROR", out)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   116
            self.assertIn("Content block expected for the &quot;rql-table&quot; "
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   117
                          "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
   118
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   119
    def test_rqltable_norset(self):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   120
        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
   121
            context = self.context(req)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   122
            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
   123
            out = rest_publish(
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   124
                context, """\
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   125
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   126
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   127
                %(rql)s""" % {'rql': rql})
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   128
            self.assertIn("System Message: WARNING", out)
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   129
            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
   130
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   131
    def test_rqltable_nooptions(self):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   132
        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
   133
            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
   134
            out = rest_publish(
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   135
                self.context(req), """\
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   136
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   137
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   138
   %(rql)s
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   139
                """ % {'rql': rql})
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   140
            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
   141
            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
   142
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   143
    def test_rqltable_vid(self):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   144
        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
   145
            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
   146
            vid = 'mytable'
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   147
            out = rest_publish(
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   148
                self.context(req), """\
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   149
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   150
   :vid: %(vid)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   151
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   152
   %(rql)s
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   153
                """ % {'rql': rql, 'vid': vid})
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   154
            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
   155
            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
   156
            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
   157
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   158
    def test_rqltable_badvid(self):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   159
        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
   160
            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
   161
            vid = 'mytabel'
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   162
            out = rest_publish(
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   163
                self.context(req), """\
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   164
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   165
   :vid: %(vid)s
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
   %(rql)s
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   168
                """ % {'rql': rql, 'vid': vid})
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   169
            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
   170
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   171
    def test_rqltable_headers(self):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   172
        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
   173
            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
   174
            headers = ["nom", "prenom", "identifiant"]
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   175
            out = rest_publish(
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   176
                self.context(req), """\
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   177
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   178
   :headers: %(headers)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   179
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   180
   %(rql)s
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   181
                """ % {'rql': rql, 'headers': ', '.join(headers)})
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   182
            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
   183
            view.headers = headers
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   184
            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
   185
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   186
    def test_rqltable_headers_missing(self):
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   187
        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
   188
            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
   189
            headers = ["nom", "", "identifiant"]
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   190
            out = rest_publish(
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   191
                self.context(req), """\
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   192
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   193
   :headers: %(headers)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   194
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   195
   %(rql)s
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   196
                """ % {'rql': rql, 'headers': ', '.join(headers)})
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   197
            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
   198
            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
   199
            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
   200
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   201
    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
   202
        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
   203
            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
   204
            headers = [" ", "prenom", ""]
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   205
            out = rest_publish(
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   206
                self.context(req), """\
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   207
.. rql-table::
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   208
   :headers: %(headers)s
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   209
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   210
   %(rql)s
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   211
                """ % {'rql': rql, 'headers': ', '.join(headers)})
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   212
            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
   213
            view.headers = [None, headers[1], None]
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   214
            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
   215
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   216
    def test_rqltable_colvids(self):
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   217
        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
   218
            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
   219
            colvids = {0: "oneline"}
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   220
            out = rest_publish(
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   221
                self.context(req), """\
9322
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   222
.. rql-table::
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   223
   :colvids: %(colvids)s
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   224
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   225
   %(rql)s
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   226
                """ % {'rql': rql,
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   227
                       'colvids': ', '.join(["%d=%s" % (k, v)
10662
10942ed172de [py3k] dict.iteritems → dict.items
Rémi Cardona <remi.cardona@logilab.fr>
parents: 9856
diff changeset
   228
                                             for k, v in colvids.items()])
9856
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   229
                   })
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   230
            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
   231
            view.cellvids = colvids
156a3fb4a884 [exttests/rest] use the new connection api
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 9517
diff changeset
   232
            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
   233
2dae5bf5ea68 [ReST] Implement a rql-table reST directive. Closes #3252856
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 8852
diff changeset
   234
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   235
if __name__ == '__main__':
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
    unittest_main()