[devtools] make migration handler easily available from CubicWebTC through .shell() method stable
authorJulien Jehannet <julien.jehannet@logilab.fr>
Fri, 05 Nov 2010 18:51:22 +0100
branchstable
changeset 6694 d9eac4fd57dc
parent 6693 65bd93b72f1e
child 6695 b714521ac66d
[devtools] make migration handler easily available from CubicWebTC through .shell() method So we are able to use shell/migration helper methods directly from test cases.
devtools/testlib.py
--- a/devtools/testlib.py	Fri Nov 12 13:47:26 2010 +0100
+++ b/devtools/testlib.py	Fri Nov 05 18:51:22 2010 +0100
@@ -184,6 +184,7 @@
     * `repo`, the repository object
     * `admlogin`, login of the admin user
     * `admpassword`, password of the admin user
+    * `shell`, create and use shell environment
     """
     appid = 'data'
     configcls = devtools.ApptestConfiguration
@@ -291,6 +292,14 @@
         """return current server side session (using default manager account)"""
         return self.repo._sessions[self._orig_cnx[0].sessionid]
 
+    def shell(self):
+        """return a shell session object"""
+        from cubicweb.server.migractions import ServerMigrationHelper
+        return ServerMigrationHelper(None, repo=self.repo, cnx=self.cnx,
+                                     interactive=False,
+                                     # hack so it don't try to load fs schema
+                                     schema=1)
+
     def set_option(self, optname, value):
         self.config.global_set_option(optname, value)
 
@@ -663,7 +672,7 @@
 
     def assertDocTestFile(self, testfile):
         # doctest returns tuple (failure_count, test_count)
-        result = self.shell.process_script(testfile)
+        result = self.shell().process_script(testfile)
         if result[0] and result[1]:
             raise self.failureException("doctest file '%s' failed"
                                         % testfile)