author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 26 Aug 2009 19:17:53 +0200 | |
branch | stable |
changeset 3028 | 6484158121b4 |
parent 1977 | 606923dff11b |
child 2773 | b2530e3e0afb |
child 4212 | ab6573088b4a |
permissions | -rw-r--r-- |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
1 |
""" |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
2 |
|
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
3 |
:organization: Logilab |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
4 |
:copyright: 2001-2009 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
5 |
:contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
6 |
:license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
7 |
""" |
0 | 8 |
from cubicweb import ConnectionError |
9 |
from cubicweb.dbapi import ProgrammingError |
|
10 |
from cubicweb.devtools.apptest import EnvBasedTC |
|
11 |
||
12 |
||
13 |
class DBAPITC(EnvBasedTC): |
|
14 |
@property |
|
15 |
def cnx(self): |
|
16 |
return self.login('anon') |
|
17 |
||
18 |
def test_public_repo_api(self): |
|
19 |
cnx = self.cnx |
|
20 |
self.assertEquals(cnx.get_schema(), self.env.repo.schema) |
|
21 |
self.assertEquals(cnx.source_defs(), {'system': {'adapter': 'native', 'uri': 'system'}}) |
|
22 |
self.restore_connection() # proper way to close cnx |
|
23 |
self.assertRaises(ProgrammingError, cnx.get_schema) |
|
24 |
self.assertRaises(ProgrammingError, cnx.source_defs) |
|
25 |
||
26 |
def test_db_api(self): |
|
27 |
cnx = self.cnx |
|
28 |
self.assertEquals(cnx.rollback(), None) |
|
29 |
self.assertEquals(cnx.commit(), None) |
|
30 |
self.restore_connection() # proper way to close cnx |
|
31 |
#self.assertEquals(cnx.close(), None) |
|
32 |
self.assertRaises(ProgrammingError, cnx.rollback) |
|
33 |
self.assertRaises(ProgrammingError, cnx.commit) |
|
34 |
self.assertRaises(ProgrammingError, cnx.close) |
|
35 |
||
36 |
def test_api(self): |
|
37 |
cnx = self.cnx |
|
38 |
self.assertEquals(cnx.user(None).login, 'anon') |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
39 |
self.assertEquals(cnx.describe(1), (u'CWGroup', u'system', None)) |
0 | 40 |
self.restore_connection() # proper way to close cnx |
41 |
self.assertRaises(ConnectionError, cnx.user, None) |
|
42 |
self.assertRaises(ConnectionError, cnx.describe, 1) |
|
43 |
||
44 |
def test_session_data_api(self): |
|
45 |
cnx = self.cnx |
|
46 |
self.assertEquals(cnx.get_session_data('data'), None) |
|
47 |
self.assertEquals(cnx.session_data(), {}) |
|
48 |
cnx.set_session_data('data', 4) |
|
49 |
self.assertEquals(cnx.get_session_data('data'), 4) |
|
50 |
self.assertEquals(cnx.session_data(), {'data': 4}) |
|
51 |
cnx.del_session_data('data') |
|
52 |
cnx.del_session_data('whatever') |
|
53 |
self.assertEquals(cnx.get_session_data('data'), None) |
|
54 |
self.assertEquals(cnx.session_data(), {}) |
|
55 |
cnx.session_data()['data'] = 4 |
|
56 |
self.assertEquals(cnx.get_session_data('data'), 4) |
|
57 |
self.assertEquals(cnx.session_data(), {'data': 4}) |
|
58 |
||
59 |
def test_shared_data_api(self): |
|
60 |
cnx = self.cnx |
|
61 |
self.assertEquals(cnx.get_shared_data('data'), None) |
|
62 |
cnx.set_shared_data('data', 4) |
|
63 |
self.assertEquals(cnx.get_shared_data('data'), 4) |
|
64 |
cnx.get_shared_data('data', pop=True) |
|
65 |
cnx.get_shared_data('whatever', pop=True) |
|
66 |
self.assertEquals(cnx.get_shared_data('data'), None) |
|
67 |
cnx.set_shared_data('data', 4) |
|
68 |
self.assertEquals(cnx.get_shared_data('data'), 4) |
|
69 |
self.restore_connection() # proper way to close cnx |
|
70 |
self.assertRaises(ConnectionError, cnx.check) |
|
71 |
self.assertRaises(ConnectionError, cnx.set_shared_data, 'data', 0) |
|
72 |
self.assertRaises(ConnectionError, cnx.get_shared_data, 'data') |
|
73 |
||
74 |
||
75 |
# class DBAPICursorTC(EnvBasedTC): |
|
76 |
||
77 |
# @property |
|
78 |
# def cursor(self): |
|
79 |
# return self.env.cnx.cursor() |
|
80 |
||
81 |
# def test_api(self): |
|
82 |
# cu = self.cursor |
|
1398
5fe84a5f7035
rename internal entity types to have CW prefix instead of E
sylvain.thenault@logilab.fr
parents:
0
diff
changeset
|
83 |
# self.assertEquals(cu.describe(1), (u'CWGroup', u'system', None)) |
0 | 84 |
# #cu.close() |
85 |
# #self.assertRaises(ConnectionError, cu.describe, 1) |
|
86 |
||
87 |
if __name__ == '__main__': |
|
88 |
from logilab.common.testlib import unittest_main |
|
89 |
unittest_main() |