author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Fri, 26 Mar 2010 06:57:52 +0100 | |
branch | stable |
changeset 5029 | f7709d28fb79 |
parent 4913 | 083b4d454192 |
child 5223 | 6abd6e3599f4 |
child 5421 | 8167de96c523 |
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 |
""" |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4768
diff
changeset
|
8 |
from __future__ import with_statement |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4768
diff
changeset
|
9 |
from copy import copy |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4768
diff
changeset
|
10 |
|
0 | 11 |
from cubicweb import ConnectionError |
12 |
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
|
13 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 14 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
15 |
class DBAPITC(CubicWebTC): |
0 | 16 |
|
17 |
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
|
18 |
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
|
19 |
self.assertEquals(cnx.get_schema(), self.repo.schema) |
0 | 20 |
self.assertEquals(cnx.source_defs(), {'system': {'adapter': 'native', 'uri': 'system'}}) |
21 |
self.restore_connection() # proper way to close cnx |
|
22 |
self.assertRaises(ProgrammingError, cnx.get_schema) |
|
23 |
self.assertRaises(ProgrammingError, cnx.source_defs) |
|
24 |
||
25 |
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
|
26 |
cnx = self.login('anon') |
0 | 27 |
self.assertEquals(cnx.rollback(), None) |
28 |
self.assertEquals(cnx.commit(), None) |
|
29 |
self.restore_connection() # proper way to close cnx |
|
30 |
#self.assertEquals(cnx.close(), None) |
|
31 |
self.assertRaises(ProgrammingError, cnx.rollback) |
|
32 |
self.assertRaises(ProgrammingError, cnx.commit) |
|
33 |
self.assertRaises(ProgrammingError, cnx.close) |
|
34 |
||
35 |
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
|
36 |
cnx = self.login('anon') |
0 | 37 |
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
|
38 |
self.assertEquals(cnx.describe(1), (u'CWGroup', u'system', None)) |
0 | 39 |
self.restore_connection() # proper way to close cnx |
4768
430b89aed996
delete pyro proxy on connection close, properly raise programming error when working on a closed connection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
40 |
self.assertRaises(ProgrammingError, cnx.user, None) |
430b89aed996
delete pyro proxy on connection close, properly raise programming error when working on a closed connection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
41 |
self.assertRaises(ProgrammingError, cnx.describe, 1) |
0 | 42 |
|
43 |
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
|
44 |
cnx = self.login('anon') |
0 | 45 |
self.assertEquals(cnx.get_session_data('data'), None) |
46 |
self.assertEquals(cnx.session_data(), {}) |
|
47 |
cnx.set_session_data('data', 4) |
|
48 |
self.assertEquals(cnx.get_session_data('data'), 4) |
|
49 |
self.assertEquals(cnx.session_data(), {'data': 4}) |
|
50 |
cnx.del_session_data('data') |
|
51 |
cnx.del_session_data('whatever') |
|
52 |
self.assertEquals(cnx.get_session_data('data'), None) |
|
53 |
self.assertEquals(cnx.session_data(), {}) |
|
54 |
cnx.session_data()['data'] = 4 |
|
55 |
self.assertEquals(cnx.get_session_data('data'), 4) |
|
56 |
self.assertEquals(cnx.session_data(), {'data': 4}) |
|
57 |
||
58 |
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
|
59 |
cnx = self.login('anon') |
0 | 60 |
self.assertEquals(cnx.get_shared_data('data'), None) |
61 |
cnx.set_shared_data('data', 4) |
|
62 |
self.assertEquals(cnx.get_shared_data('data'), 4) |
|
63 |
cnx.get_shared_data('data', pop=True) |
|
64 |
cnx.get_shared_data('whatever', pop=True) |
|
65 |
self.assertEquals(cnx.get_shared_data('data'), None) |
|
66 |
cnx.set_shared_data('data', 4) |
|
67 |
self.assertEquals(cnx.get_shared_data('data'), 4) |
|
68 |
self.restore_connection() # proper way to close cnx |
|
4768
430b89aed996
delete pyro proxy on connection close, properly raise programming error when working on a closed connection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
69 |
self.assertRaises(ProgrammingError, cnx.check) |
430b89aed996
delete pyro proxy on connection close, properly raise programming error when working on a closed connection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
70 |
self.assertRaises(ProgrammingError, cnx.set_shared_data, 'data', 0) |
430b89aed996
delete pyro proxy on connection close, properly raise programming error when working on a closed connection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
4252
diff
changeset
|
71 |
self.assertRaises(ProgrammingError, cnx.get_shared_data, 'data') |
0 | 72 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4768
diff
changeset
|
73 |
|
0 | 74 |
if __name__ == '__main__': |
75 |
from logilab.common.testlib import unittest_main |
|
76 |
unittest_main() |