author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Thu, 28 Nov 2013 18:55:24 +0100 (2013-11-28) | |
branch | stable |
changeset 9334 | ea12401c0a68 |
parent 6340 | 470d8e828fda |
child 9335 | 7da91456be2c |
permissions | -rw-r--r-- |
5421
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4831
diff
changeset
|
1 |
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
8167de96c523
proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
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:
4831
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
0 | 18 |
"""unit tests for module cubicweb.server.sqlutils |
19 |
""" |
|
20 |
||
21 |
import sys |
|
22 |
||
23 |
from logilab.common.testlib import TestCase, unittest_main |
|
24 |
||
25 |
from cubicweb.server.sqlutils import * |
|
26 |
||
9334
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
27 |
from cubicweb.devtools.testlib import CubicWebTC |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
28 |
|
0 | 29 |
BASE_CONFIG = { |
30 |
'db-driver' : 'Postgres', |
|
31 |
'db-host' : 'crater', |
|
32 |
'db-name' : 'cubicweb2_test', |
|
33 |
'db-user' : 'toto', |
|
34 |
'db-upassword' : 'toto', |
|
35 |
} |
|
36 |
||
37 |
class SQLAdapterMixInTC(TestCase): |
|
38 |
||
39 |
def test_init(self): |
|
40 |
o = SQLAdapterMixIn(BASE_CONFIG) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
41 |
self.assertEqual(o.dbhelper.dbencoding, 'UTF-8') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
42 |
|
0 | 43 |
def test_init_encoding(self): |
44 |
config = BASE_CONFIG.copy() |
|
45 |
config['db-encoding'] = 'ISO-8859-1' |
|
46 |
o = SQLAdapterMixIn(config) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5424
diff
changeset
|
47 |
self.assertEqual(o.dbhelper.dbencoding, 'ISO-8859-1') |
1802
d628defebc17
delete-trailing-whitespace + some copyright update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1016
diff
changeset
|
48 |
|
9334
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
49 |
|
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
50 |
class SQLUtilsTC(CubicWebTC): |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
51 |
|
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
52 |
def test_group_concat(self): |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
53 |
req = self.request() |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
54 |
u = req.create_entity('CWUser', login=u'toto', upassword=u'', |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
55 |
in_group=req.execute('CWGroup G WHERE G name "managers"').rows[0][0]) |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
56 |
rset = self.execute('Any L,GROUP_CONCAT(G) GROUPBY L WHERE X login L,' |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
57 |
'X in_group G, G name GN, NOT G name "users"') |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
58 |
self.assertEqual([[u'admin', u'3'], [u'anon', u'2'], [u'toto', u'3']], |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
59 |
rset.rows) |
ea12401c0a68
[sqlutils] avoid a crash with sqlite when using group_concat (closes #3331906)
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
6340
diff
changeset
|
60 |
|
0 | 61 |
if __name__ == '__main__': |
62 |
unittest_main() |