author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Thu, 18 Feb 2010 14:07:56 +0100 | |
branch | stable |
changeset 4638 | c7d2145abf61 |
parent 4252 | 6c4f109c2b03 |
child 4768 | 430b89aed996 |
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 |
4212
ab6573088b4a
update copyright: welcome 2010
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1977
diff
changeset
|
4 |
:copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2. |
1977
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 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
10 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 11 |
|
12 |
||
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
13 |
class DBAPITC(CubicWebTC): |
0 | 14 |
|
15 |
def test_public_repo_api(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
16 |
cnx = self.login('anon') |
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
17 |
self.assertEquals(cnx.get_schema(), self.repo.schema) |
0 | 18 |
self.assertEquals(cnx.source_defs(), {'system': {'adapter': 'native', 'uri': 'system'}}) |
19 |
self.restore_connection() # proper way to close cnx |
|
20 |
self.assertRaises(ProgrammingError, cnx.get_schema) |
|
21 |
self.assertRaises(ProgrammingError, cnx.source_defs) |
|
22 |
||
23 |
def test_db_api(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
24 |
cnx = self.login('anon') |
0 | 25 |
self.assertEquals(cnx.rollback(), None) |
26 |
self.assertEquals(cnx.commit(), None) |
|
27 |
self.restore_connection() # proper way to close cnx |
|
28 |
#self.assertEquals(cnx.close(), None) |
|
29 |
self.assertRaises(ProgrammingError, cnx.rollback) |
|
30 |
self.assertRaises(ProgrammingError, cnx.commit) |
|
31 |
self.assertRaises(ProgrammingError, cnx.close) |
|
32 |
||
33 |
def test_api(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
34 |
cnx = self.login('anon') |
0 | 35 |
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
|
36 |
self.assertEquals(cnx.describe(1), (u'CWGroup', u'system', None)) |
0 | 37 |
self.restore_connection() # proper way to close cnx |
38 |
self.assertRaises(ConnectionError, cnx.user, None) |
|
39 |
self.assertRaises(ConnectionError, cnx.describe, 1) |
|
40 |
||
41 |
def test_session_data_api(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
42 |
cnx = self.login('anon') |
0 | 43 |
self.assertEquals(cnx.get_session_data('data'), None) |
44 |
self.assertEquals(cnx.session_data(), {}) |
|
45 |
cnx.set_session_data('data', 4) |
|
46 |
self.assertEquals(cnx.get_session_data('data'), 4) |
|
47 |
self.assertEquals(cnx.session_data(), {'data': 4}) |
|
48 |
cnx.del_session_data('data') |
|
49 |
cnx.del_session_data('whatever') |
|
50 |
self.assertEquals(cnx.get_session_data('data'), None) |
|
51 |
self.assertEquals(cnx.session_data(), {}) |
|
52 |
cnx.session_data()['data'] = 4 |
|
53 |
self.assertEquals(cnx.get_session_data('data'), 4) |
|
54 |
self.assertEquals(cnx.session_data(), {'data': 4}) |
|
55 |
||
56 |
def test_shared_data_api(self): |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
57 |
cnx = self.login('anon') |
0 | 58 |
self.assertEquals(cnx.get_shared_data('data'), None) |
59 |
cnx.set_shared_data('data', 4) |
|
60 |
self.assertEquals(cnx.get_shared_data('data'), 4) |
|
61 |
cnx.get_shared_data('data', pop=True) |
|
62 |
cnx.get_shared_data('whatever', pop=True) |
|
63 |
self.assertEquals(cnx.get_shared_data('data'), None) |
|
64 |
cnx.set_shared_data('data', 4) |
|
65 |
self.assertEquals(cnx.get_shared_data('data'), 4) |
|
66 |
self.restore_connection() # proper way to close cnx |
|
67 |
self.assertRaises(ConnectionError, cnx.check) |
|
68 |
self.assertRaises(ConnectionError, cnx.set_shared_data, 'data', 0) |
|
69 |
self.assertRaises(ConnectionError, cnx.get_shared_data, 'data') |
|
70 |
||
71 |
if __name__ == '__main__': |
|
72 |
from logilab.common.testlib import unittest_main |
|
73 |
unittest_main() |