ext/test/unittest_rest.py
branchstable
changeset 8255 25a00e4a8722
parent 7732 5430d0db52ab
child 8852 59a29405688c
equal deleted inserted replaced
8254:eff5b930998d 8255:25a00e4a8722
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    13 # FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
    14 # details.
    14 # details.
    15 #
    15 #
    16 # You should have received a copy of the GNU Lesser General Public License along
    16 # You should have received a copy of the GNU Lesser General Public License along
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    17 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
    18 """
       
    19 
       
    20 """
       
    21 from logilab.common.testlib import unittest_main
    18 from logilab.common.testlib import unittest_main
    22 from cubicweb.devtools.testlib import CubicWebTC
    19 from cubicweb.devtools.testlib import CubicWebTC
    23 
    20 
    24 from cubicweb.ext.rest import rest_publish
    21 from cubicweb.ext.rest import rest_publish
    25 
    22 
    58 
    55 
    59 
    56 
    60     def test_rql_role_with_vid(self):
    57     def test_rql_role_with_vid(self):
    61         context = self.context()
    58         context = self.context()
    62         out = rest_publish(context, ':rql:`Any X WHERE X is CWUser:table`')
    59         out = rest_publish(context, ':rql:`Any X WHERE X is CWUser:table`')
    63         self.assert_(out.endswith('<a href="http://testing.fr/cubicweb/cwuser/anon" title="">anon</a>'
    60         self.assertTrue(out.endswith('<a href="http://testing.fr/cubicweb/cwuser/anon" title="">anon</a>'
    64                                   '</td></tr></tbody></table></div>\n</div>\n</p>\n'))
    61                                      '</td></tr>\n</tbody></table></div></p>\n'))
    65 
    62 
    66     def test_rql_role_with_vid_empty_rset(self):
    63     def test_rql_role_with_vid_empty_rset(self):
    67         context = self.context()
    64         context = self.context()
    68         out = rest_publish(context, ':rql:`Any X WHERE X is CWUser, X login "nono":table`')
    65         out = rest_publish(context, ':rql:`Any X WHERE X is CWUser, X login "nono":table`')
    69         self.assert_(out.endswith('<p><div class="searchMessage"><strong>No result matching query</strong></div>\n</p>\n'))
    66         self.assertTrue(out.endswith('<p><div class="searchMessage"><strong>No result matching query</strong></div>\n</p>\n'))
    70 
    67 
    71     def test_rql_role_with_unknown_vid(self):
    68     def test_rql_role_with_unknown_vid(self):
    72         context = self.context()
    69         context = self.context()
    73         out = rest_publish(context, ':rql:`Any X WHERE X is CWUser:toto`')
    70         out = rest_publish(context, ':rql:`Any X WHERE X is CWUser:toto`')
    74         self.assert_(out.startswith("<p>an error occured while interpreting this rql directive: ObjectNotFound(u'toto',)</p>"))
    71         self.assertTrue(out.startswith("<p>an error occured while interpreting this rql directive: ObjectNotFound(u'toto',)</p>"))
    75 
    72 
    76     def test_rql_role_without_vid(self):
    73     def test_rql_role_without_vid(self):
    77         context = self.context()
    74         context = self.context()
    78         out = rest_publish(context, ':rql:`Any X WHERE X is CWUser`')
    75         out = rest_publish(context, ':rql:`Any X WHERE X is CWUser`')
    79         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')
    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')
    80 
    77 
    81 if __name__ == '__main__':
    78 if __name__ == '__main__':
    82     unittest_main()
    79     unittest_main()