16 # |
16 # |
17 # You should have received a copy of the GNU Lesser General Public License along |
17 # You should have received a copy of the GNU Lesser General Public License along |
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
19 """unit tests for module cubicweb.rset""" |
19 """unit tests for module cubicweb.rset""" |
20 |
20 |
21 from six import string_types |
21 import pickle |
22 from six.moves import cPickle as pickle |
22 from urllib.parse import urlsplit |
23 from six.moves.urllib.parse import urlsplit |
|
24 |
23 |
25 from rql import parse |
24 from rql import parse |
26 |
25 |
27 from logilab.common.testlib import TestCase, unittest_main, mock_object |
26 from logilab.common.testlib import TestCase, unittest_main, mock_object |
28 |
27 |
653 self.assertEqual(rset.related_entity(0, 0), (None, None)) |
652 self.assertEqual(rset.related_entity(0, 0), (None, None)) |
654 |
653 |
655 def test_str(self): |
654 def test_str(self): |
656 with self.admin_access.web_request() as req: |
655 with self.admin_access.web_request() as req: |
657 rset = req.execute('(Any X,N WHERE X is CWGroup, X name N)') |
656 rset = req.execute('(Any X,N WHERE X is CWGroup, X name N)') |
658 self.assertIsInstance(str(rset), string_types) |
657 self.assertIsInstance(str(rset), str) |
659 self.assertEqual(len(str(rset).splitlines()), 1) |
658 self.assertEqual(len(str(rset).splitlines()), 1) |
660 |
659 |
661 def test_repr(self): |
660 def test_repr(self): |
662 with self.admin_access.web_request() as req: |
661 with self.admin_access.web_request() as req: |
663 rset = req.execute('(Any X,N WHERE X is CWGroup, X name N)') |
662 rset = req.execute('(Any X,N WHERE X is CWGroup, X name N)') |
664 self.assertIsInstance(repr(rset), string_types) |
663 self.assertIsInstance(repr(rset), str) |
665 self.assertTrue(len(repr(rset).splitlines()) > 1) |
664 self.assertTrue(len(repr(rset).splitlines()) > 1) |
666 |
665 |
667 rset = req.execute('(Any X WHERE X is CWGroup, X name "managers")') |
666 rset = req.execute('(Any X WHERE X is CWGroup, X name "managers")') |
668 self.assertIsInstance(str(rset), string_types) |
667 self.assertIsInstance(str(rset), str) |
669 self.assertEqual(len(str(rset).splitlines()), 1) |
668 self.assertEqual(len(str(rset).splitlines()), 1) |
670 |
669 |
671 def test_slice(self): |
670 def test_slice(self): |
672 rs = ResultSet([[12000, 'adim', u'Adim chez les pinguins'], |
671 rs = ResultSet([[12000, 'adim', u'Adim chez les pinguins'], |
673 [12000, 'adim', u'Jardiner facile'], |
672 [12000, 'adim', u'Jardiner facile'], |