|
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
|
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
3 # |
|
4 # This file is part of CubicWeb. |
|
5 # |
|
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
|
7 # terms of the GNU Lesser General Public License as published by the Free |
|
8 # Software Foundation, either version 2.1 of the License, or (at your option) |
|
9 # any later version. |
|
10 # |
|
11 # logilab-common is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
|
14 # details. |
|
15 # |
|
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/>. |
1 """ |
18 """ |
2 |
19 |
3 :organization: Logilab |
|
4 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
|
5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
|
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
|
7 """ |
20 """ |
|
21 from __future__ import with_statement |
|
22 from copy import copy |
|
23 |
8 from cubicweb import ConnectionError |
24 from cubicweb import ConnectionError |
9 from cubicweb.dbapi import ProgrammingError |
25 from cubicweb.dbapi import ProgrammingError |
10 from cubicweb.devtools.testlib import CubicWebTC |
26 from cubicweb.devtools.testlib import CubicWebTC |
11 |
|
12 |
27 |
13 class DBAPITC(CubicWebTC): |
28 class DBAPITC(CubicWebTC): |
14 |
29 |
15 def test_public_repo_api(self): |
30 def test_public_repo_api(self): |
16 cnx = self.login('anon') |
31 cnx = self.login('anon') |
33 def test_api(self): |
48 def test_api(self): |
34 cnx = self.login('anon') |
49 cnx = self.login('anon') |
35 self.assertEquals(cnx.user(None).login, 'anon') |
50 self.assertEquals(cnx.user(None).login, 'anon') |
36 self.assertEquals(cnx.describe(1), (u'CWGroup', u'system', None)) |
51 self.assertEquals(cnx.describe(1), (u'CWGroup', u'system', None)) |
37 self.restore_connection() # proper way to close cnx |
52 self.restore_connection() # proper way to close cnx |
38 self.assertRaises(ConnectionError, cnx.user, None) |
53 self.assertRaises(ProgrammingError, cnx.user, None) |
39 self.assertRaises(ConnectionError, cnx.describe, 1) |
54 self.assertRaises(ProgrammingError, cnx.describe, 1) |
40 |
55 |
41 def test_session_data_api(self): |
56 def test_session_data_api(self): |
42 cnx = self.login('anon') |
57 cnx = self.login('anon') |
43 self.assertEquals(cnx.get_session_data('data'), None) |
58 self.assertEquals(cnx.get_session_data('data'), None) |
44 self.assertEquals(cnx.session_data(), {}) |
59 self.assertEquals(cnx.session_data(), {}) |
62 cnx.get_shared_data('whatever', pop=True) |
77 cnx.get_shared_data('whatever', pop=True) |
63 self.assertEquals(cnx.get_shared_data('data'), None) |
78 self.assertEquals(cnx.get_shared_data('data'), None) |
64 cnx.set_shared_data('data', 4) |
79 cnx.set_shared_data('data', 4) |
65 self.assertEquals(cnx.get_shared_data('data'), 4) |
80 self.assertEquals(cnx.get_shared_data('data'), 4) |
66 self.restore_connection() # proper way to close cnx |
81 self.restore_connection() # proper way to close cnx |
67 self.assertRaises(ConnectionError, cnx.check) |
82 self.assertRaises(ProgrammingError, cnx.check) |
68 self.assertRaises(ConnectionError, cnx.set_shared_data, 'data', 0) |
83 self.assertRaises(ProgrammingError, cnx.set_shared_data, 'data', 0) |
69 self.assertRaises(ConnectionError, cnx.get_shared_data, 'data') |
84 self.assertRaises(ProgrammingError, cnx.get_shared_data, 'data') |
|
85 |
70 |
86 |
71 if __name__ == '__main__': |
87 if __name__ == '__main__': |
72 from logilab.common.testlib import unittest_main |
88 from logilab.common.testlib import unittest_main |
73 unittest_main() |
89 unittest_main() |