13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
13 # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more |
14 # details. |
14 # details. |
15 # |
15 # |
16 # You should have received a copy of the GNU Lesser General Public License along |
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/>. |
17 # with CubicWeb. If not, see <http://www.gnu.org/licenses/>. |
18 """ |
18 """unittest for cubicweb.dbapi""" |
19 |
19 |
20 """ |
|
21 from __future__ import with_statement |
20 from __future__ import with_statement |
|
21 |
22 from copy import copy |
22 from copy import copy |
23 |
23 |
24 from cubicweb import ConnectionError |
24 from logilab.common import tempattr |
|
25 |
|
26 from cubicweb import ConnectionError, cwconfig |
25 from cubicweb.dbapi import ProgrammingError |
27 from cubicweb.dbapi import ProgrammingError |
26 from cubicweb.devtools.testlib import CubicWebTC |
28 from cubicweb.devtools.testlib import CubicWebTC |
27 |
29 |
28 class DBAPITC(CubicWebTC): |
30 class DBAPITC(CubicWebTC): |
29 |
31 |
30 def test_public_repo_api(self): |
32 def test_public_repo_api(self): |
31 cnx = self.login('anon') |
33 cnx = self.login('anon') |
32 self.assertEqual(cnx.get_schema(), self.repo.schema) |
34 self.assertEqual(cnx.get_schema(), self.repo.schema) |
33 self.assertEqual(cnx.source_defs(), {'system': {'adapter': 'native', 'uri': 'system'}}) |
35 self.assertEqual(cnx.source_defs(), {'system': {'type': 'native', 'uri': 'system'}}) |
34 self.restore_connection() # proper way to close cnx |
36 self.restore_connection() # proper way to close cnx |
35 self.assertRaises(ProgrammingError, cnx.get_schema) |
37 self.assertRaises(ProgrammingError, cnx.get_schema) |
36 self.assertRaises(ProgrammingError, cnx.source_defs) |
38 self.assertRaises(ProgrammingError, cnx.source_defs) |
37 |
39 |
38 def test_db_api(self): |
40 def test_db_api(self): |
46 self.assertRaises(ProgrammingError, cnx.close) |
48 self.assertRaises(ProgrammingError, cnx.close) |
47 |
49 |
48 def test_api(self): |
50 def test_api(self): |
49 cnx = self.login('anon') |
51 cnx = self.login('anon') |
50 self.assertEqual(cnx.user(None).login, 'anon') |
52 self.assertEqual(cnx.user(None).login, 'anon') |
51 self.assertEqual(cnx.describe(1), (u'CWGroup', u'system', None)) |
53 self.assertEqual(cnx.describe(1), (u'CWSource', u'system', None)) |
52 self.restore_connection() # proper way to close cnx |
54 self.restore_connection() # proper way to close cnx |
53 self.assertRaises(ProgrammingError, cnx.user, None) |
55 self.assertRaises(ProgrammingError, cnx.user, None) |
54 self.assertRaises(ProgrammingError, cnx.describe, 1) |
56 self.assertRaises(ProgrammingError, cnx.describe, 1) |
55 |
57 |
56 def test_shared_data_api(self): |
58 def test_shared_data_api(self): |
66 self.restore_connection() # proper way to close cnx |
68 self.restore_connection() # proper way to close cnx |
67 self.assertRaises(ProgrammingError, cnx.check) |
69 self.assertRaises(ProgrammingError, cnx.check) |
68 self.assertRaises(ProgrammingError, cnx.set_shared_data, 'data', 0) |
70 self.assertRaises(ProgrammingError, cnx.set_shared_data, 'data', 0) |
69 self.assertRaises(ProgrammingError, cnx.get_shared_data, 'data') |
71 self.assertRaises(ProgrammingError, cnx.get_shared_data, 'data') |
70 |
72 |
|
73 def test_web_compatible_request(self): |
|
74 config = cwconfig.CubicWebNoAppConfiguration() |
|
75 with tempattr(self.cnx.vreg, 'config', config): |
|
76 self.cnx.use_web_compatible_requests('http://perdu.com') |
|
77 req = self.cnx.request() |
|
78 self.assertEqual(req.base_url(), 'http://perdu.com') |
|
79 self.assertEqual(req.from_controller(), 'view') |
|
80 self.assertEqual(req.relative_path(), '') |
|
81 req.ajax_replace_url('domid') # don't crash |
|
82 req.user.cw_adapt_to('IBreadCrumbs') # don't crash |
71 |
83 |
72 if __name__ == '__main__': |
84 if __name__ == '__main__': |
73 from logilab.common.testlib import unittest_main |
85 from logilab.common.testlib import unittest_main |
74 unittest_main() |
86 unittest_main() |