server/test/unittest_sqlutils.py
changeset 9340 b1e933b0e850
parent 9335 7da91456be2c
child 9805 1b864f5541cf
equal deleted inserted replaced
9322:2dae5bf5ea68 9340:b1e933b0e850
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # -*- coding: utf-8 -*-
       
     2 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     4 #
     4 # This file is part of CubicWeb.
     5 # This file is part of CubicWeb.
     5 #
     6 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     7 # CubicWeb is free software: you can redistribute it and/or modify it under the
    22 
    23 
    23 from logilab.common.testlib import TestCase, unittest_main
    24 from logilab.common.testlib import TestCase, unittest_main
    24 
    25 
    25 from cubicweb.server.sqlutils import *
    26 from cubicweb.server.sqlutils import *
    26 
    27 
       
    28 from cubicweb.devtools.testlib import CubicWebTC
       
    29 
    27 BASE_CONFIG = {
    30 BASE_CONFIG = {
    28     'db-driver' : 'Postgres',
    31     'db-driver' : 'Postgres',
    29     'db-host'   : 'crater',
    32     'db-host'   : 'crater',
    30     'db-name'   : 'cubicweb2_test',
    33     'db-name'   : 'cubicweb2_test',
    31     'db-user'   : 'toto',
    34     'db-user'   : 'toto',
    42         config = BASE_CONFIG.copy()
    45         config = BASE_CONFIG.copy()
    43         config['db-encoding'] = 'ISO-8859-1'
    46         config['db-encoding'] = 'ISO-8859-1'
    44         o = SQLAdapterMixIn(config)
    47         o = SQLAdapterMixIn(config)
    45         self.assertEqual(o.dbhelper.dbencoding, 'ISO-8859-1')
    48         self.assertEqual(o.dbhelper.dbencoding, 'ISO-8859-1')
    46 
    49 
       
    50 
       
    51 class SQLUtilsTC(CubicWebTC):
       
    52 
       
    53     def test_group_concat(self):
       
    54         req = self.request()
       
    55         g = req.create_entity('CWGroup', name=u'héhé')
       
    56         u = req.create_entity('CWUser', login=u'toto', upassword=u'',
       
    57                               in_group=g.eid)
       
    58         rset = self.execute(u'Any L,GROUP_CONCAT(G) GROUPBY L WHERE X login L,'
       
    59                             u'X in_group G, G name GN, NOT G name IN ("users", "héhé")')
       
    60         self.assertEqual([[u'admin', u'3'], [u'anon', u'2']],
       
    61                          rset.rows)
       
    62         rset = self.execute('Any L,GROUP_CONCAT(GN) GROUPBY L WHERE X login L,'
       
    63                             'X in_group G, G name GN, NOT G name "users"')
       
    64         self.assertEqual([[u'admin', u'managers'], [u'anon', u'guests'], [u'toto', u'héhé']],
       
    65                          rset.rows)
       
    66 
    47 if __name__ == '__main__':
    67 if __name__ == '__main__':
    48     unittest_main()
    68     unittest_main()