author | Aurelien Campeas <aurelien.campeas@logilab.fr> |
Wed, 26 Oct 2011 17:58:21 +0200 | |
branch | stable |
changeset 8025 | 11caeed5ae80 |
parent 7554 | fdace9d67d96 |
child 8366 | 6599f69bb846 |
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
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:
4913
diff
changeset
|
17 |
# with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
6415 | 18 |
"""unittest for cubicweb.dbapi""" |
1977
606923dff11b
big bunch of copyright / docstring update
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
1398
diff
changeset
|
19 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4768
diff
changeset
|
20 |
from __future__ import with_statement |
6581
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
21 |
|
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4768
diff
changeset
|
22 |
from copy import copy |
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4768
diff
changeset
|
23 |
|
6581
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
24 |
from logilab.common import tempattr |
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
25 |
|
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
26 |
from cubicweb import ConnectionError, cwconfig |
0 | 27 |
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
|
28 |
from cubicweb.devtools.testlib import CubicWebTC |
0 | 29 |
|
2773
b2530e3e0afb
[testlib] #345052 and #344207: major test lib refactoring/cleanup + update usage
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
1977
diff
changeset
|
30 |
class DBAPITC(CubicWebTC): |
0 | 31 |
|
32 |
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
|
33 |
cnx = self.login('anon') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
34 |
self.assertEqual(cnx.get_schema(), self.repo.schema) |
7554 | 35 |
self.assertEqual(cnx.source_defs(), {'system': {'type': 'native', 'uri': 'system', |
36 |
'use-cwuri-as-url': False}}) |
|
0 | 37 |
self.restore_connection() # proper way to close cnx |
38 |
self.assertRaises(ProgrammingError, cnx.get_schema) |
|
39 |
self.assertRaises(ProgrammingError, cnx.source_defs) |
|
40 |
||
41 |
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
|
42 |
cnx = self.login('anon') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
43 |
self.assertEqual(cnx.rollback(), None) |
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
44 |
self.assertEqual(cnx.commit(), None) |
0 | 45 |
self.restore_connection() # proper way to close cnx |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
46 |
#self.assertEqual(cnx.close(), None) |
0 | 47 |
self.assertRaises(ProgrammingError, cnx.rollback) |
48 |
self.assertRaises(ProgrammingError, cnx.commit) |
|
49 |
self.assertRaises(ProgrammingError, cnx.close) |
|
50 |
||
51 |
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
|
52 |
cnx = self.login('anon') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
53 |
self.assertEqual(cnx.user(None).login, 'anon') |
6427
c8a5ac2d1eaa
[schema / sources] store data sources as cubicweb entities
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6415
diff
changeset
|
54 |
self.assertEqual(cnx.describe(1), (u'CWSource', u'system', None)) |
0 | 55 |
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
|
56 |
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
|
57 |
self.assertRaises(ProgrammingError, cnx.describe, 1) |
0 | 58 |
|
59 |
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
|
60 |
cnx = self.login('anon') |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
61 |
self.assertEqual(cnx.get_shared_data('data'), None) |
0 | 62 |
cnx.set_shared_data('data', 4) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
63 |
self.assertEqual(cnx.get_shared_data('data'), 4) |
0 | 64 |
cnx.get_shared_data('data', pop=True) |
65 |
cnx.get_shared_data('whatever', pop=True) |
|
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
66 |
self.assertEqual(cnx.get_shared_data('data'), None) |
0 | 67 |
cnx.set_shared_data('data', 4) |
6340
470d8e828fda
[test] update test to unittest2 api (still using lgc.testlib though)
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
5426
diff
changeset
|
68 |
self.assertEqual(cnx.get_shared_data('data'), 4) |
0 | 69 |
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
|
70 |
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
|
71 |
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
|
72 |
self.assertRaises(ProgrammingError, cnx.get_shared_data, 'data') |
0 | 73 |
|
6581
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
74 |
def test_web_compatible_request(self): |
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
75 |
config = cwconfig.CubicWebNoAppConfiguration() |
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
76 |
with tempattr(self.cnx.vreg, 'config', config): |
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
77 |
self.cnx.use_web_compatible_requests('http://perdu.com') |
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
78 |
req = self.cnx.request() |
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
79 |
self.assertEqual(req.base_url(), 'http://perdu.com') |
6613
e7ff604491b2
[dbapi] web request compatibility fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6581
diff
changeset
|
80 |
self.assertEqual(req.from_controller(), 'view') |
e7ff604491b2
[dbapi] web request compatibility fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6581
diff
changeset
|
81 |
self.assertEqual(req.relative_path(), '') |
6581
4a3b264589dc
[dbapi] enhanced web compatible request when using dbapi
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6427
diff
changeset
|
82 |
req.ajax_replace_url('domid') # don't crash |
6613
e7ff604491b2
[dbapi] web request compatibility fixes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents:
6581
diff
changeset
|
83 |
req.user.cw_adapt_to('IBreadCrumbs') # don't crash |
4913
083b4d454192
server/web api for accessing to deleted_entites
Katia Saurfelt <katia.saurfelt@logilab.fr>
parents:
4768
diff
changeset
|
84 |
|
0 | 85 |
if __name__ == '__main__': |
86 |
from logilab.common.testlib import unittest_main |
|
87 |
unittest_main() |