test/unittest_dbapi.py
brancholdstable
changeset 7074 e4580e5f0703
parent 6613 e7ff604491b2
child 7554 fdace9d67d96
--- a/test/unittest_dbapi.py	Fri Dec 10 12:17:18 2010 +0100
+++ b/test/unittest_dbapi.py	Fri Mar 11 09:46:45 2011 +0100
@@ -15,13 +15,15 @@
 #
 # You should have received a copy of the GNU Lesser General Public License along
 # with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
-"""
+"""unittest for cubicweb.dbapi"""
 
-"""
 from __future__ import with_statement
+
 from copy import copy
 
-from cubicweb import ConnectionError
+from logilab.common import tempattr
+
+from cubicweb import ConnectionError, cwconfig
 from cubicweb.dbapi import ProgrammingError
 from cubicweb.devtools.testlib import CubicWebTC
 
@@ -30,7 +32,7 @@
     def test_public_repo_api(self):
         cnx = self.login('anon')
         self.assertEqual(cnx.get_schema(), self.repo.schema)
-        self.assertEqual(cnx.source_defs(), {'system': {'adapter': 'native', 'uri': 'system'}})
+        self.assertEqual(cnx.source_defs(), {'system': {'type': 'native', 'uri': 'system'}})
         self.restore_connection() # proper way to close cnx
         self.assertRaises(ProgrammingError, cnx.get_schema)
         self.assertRaises(ProgrammingError, cnx.source_defs)
@@ -48,7 +50,7 @@
     def test_api(self):
         cnx = self.login('anon')
         self.assertEqual(cnx.user(None).login, 'anon')
-        self.assertEqual(cnx.describe(1), (u'CWGroup', u'system', None))
+        self.assertEqual(cnx.describe(1), (u'CWSource', u'system', None))
         self.restore_connection() # proper way to close cnx
         self.assertRaises(ProgrammingError, cnx.user, None)
         self.assertRaises(ProgrammingError, cnx.describe, 1)
@@ -68,6 +70,16 @@
         self.assertRaises(ProgrammingError, cnx.set_shared_data, 'data', 0)
         self.assertRaises(ProgrammingError, cnx.get_shared_data, 'data')
 
+    def test_web_compatible_request(self):
+        config = cwconfig.CubicWebNoAppConfiguration()
+        with tempattr(self.cnx.vreg, 'config', config):
+            self.cnx.use_web_compatible_requests('http://perdu.com')
+            req = self.cnx.request()
+            self.assertEqual(req.base_url(), 'http://perdu.com')
+            self.assertEqual(req.from_controller(), 'view')
+            self.assertEqual(req.relative_path(), '')
+            req.ajax_replace_url('domid') # don't crash
+            req.user.cw_adapt_to('IBreadCrumbs') # don't crash
 
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main