set removedeps to False by default, raise an exception instead of a simple assertion for error, more remove_cube tests stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 19 Jun 2009 08:47:05 +0200
branchstable
changeset 2124 5a0b02f37b23
parent 2122 4ea13a828513
child 2125 19861294506f
set removedeps to False by default, raise an exception instead of a simple assertion for error, more remove_cube tests
common/migration.py
server/migractions.py
server/test/unittest_migractions.py
--- a/common/migration.py	Fri Jun 19 08:29:22 2009 +0200
+++ b/common/migration.py	Fri Jun 19 08:47:05 2009 +0200
@@ -17,6 +17,8 @@
 from logilab.common.decorators import cached
 from logilab.common.configuration import REQUIRED, read_old_config
 
+from cubicweb import ConfigurationError
+
 
 def migration_files(config, toupgrade):
     """return an orderer list of path of scripts to execute to upgrade
@@ -328,7 +330,7 @@
             self.config.add_cubes(newcubes)
         return newcubes
 
-    def cmd_remove_cube(self, cube, removedeps=True):
+    def cmd_remove_cube(self, cube, removedeps=False):
         if removedeps:
             toremove = self.config.expand_cubes([cube])
         else:
@@ -337,8 +339,9 @@
         basecubes = [c for c in origcubes if not c in toremove]
         self.config._cubes = tuple(self.config.expand_cubes(basecubes))
         removed = [p for p in origcubes if not p in self.config._cubes]
-        assert cube in removed, \
-               "can't remove cube %s, used as a dependancy" % cube
+        if not cube in removed:
+            raise ConfigurationError("can't remove cube %s, "
+                                     "used as a dependency" % cube)
         return removed
 
     def rewrite_configuration(self):
--- a/server/migractions.py	Fri Jun 19 08:29:22 2009 +0200
+++ b/server/migractions.py	Fri Jun 19 08:47:05 2009 +0200
@@ -523,7 +523,7 @@
             self.exec_event_script('postcreate', self.config.cube_dir(pack))
             self.commit()
 
-    def cmd_remove_cube(self, cube, removedeps=True):
+    def cmd_remove_cube(self, cube, removedeps=False):
         removedcubes = super(ServerMigrationHelper, self).cmd_remove_cube(
             cube, removedeps)
         if not removedcubes:
--- a/server/test/unittest_migractions.py	Fri Jun 19 08:29:22 2009 +0200
+++ b/server/test/unittest_migractions.py	Fri Jun 19 08:47:05 2009 +0200
@@ -7,6 +7,7 @@
 from logilab.common.testlib import TestCase, unittest_main
 from cubicweb.devtools.apptest import RepositoryBasedTC, get_versions
 
+from cubicweb import ConfigurationError
 from cubicweb.schema import CubicWebSchemaLoader
 from cubicweb.server.sqlutils import SQL_PREFIX
 from cubicweb.server.repository import Repository
@@ -365,7 +366,7 @@
         finally:
             self.mh.cmd_set_size_constraint('CWEType', 'description', None)
 
-    def test_add_remove_cube(self):
+    def test_add_remove_cube_and_deps(self):
         cubes = set(self.config.cubes())
         schema = self.repo.schema
         self.assertEquals(sorted(schema['see_also']._rproperties.keys()),
@@ -374,11 +375,10 @@
                                   ('Note', 'Note'), ('Note', 'Bookmark')]))
         try:
             try:
-                self.mh.cmd_remove_cube('email')
+                self.mh.cmd_remove_cube('email', removedeps=True)
                 # file was there because it's an email dependancy, should have been removed
-                cubes.remove('email')
-                cubes.remove('file')
-                self.assertEquals(set(self.config.cubes()), cubes)
+                self.failIf('email' in self.config.cubes())
+                self.failIf('file' in self.config.cubes())
                 for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image',
                                'sender', 'in_thread', 'reply_to', 'data_format'):
                     self.failIf(ertype in schema, ertype)
@@ -392,17 +392,14 @@
                 self.assertEquals(sorted(schema['see_also'].objects()), ['Bookmark', 'Folder', 'Note'])
                 self.assertEquals(self.execute('Any X WHERE X pkey "system.version.email"').rowcount, 0)
                 self.assertEquals(self.execute('Any X WHERE X pkey "system.version.file"').rowcount, 0)
-                self.failIf('email' in self.config.cubes())
-                self.failIf('file' in self.config.cubes())
             except :
                 import traceback
                 traceback.print_exc()
                 raise
         finally:
             self.mh.cmd_add_cube('email')
-            cubes.add('email')
-            cubes.add('file')
-            self.assertEquals(set(self.config.cubes()), cubes)
+            self.failUnless('email' in self.config.cubes())
+            self.failUnless('file' in self.config.cubes())
             for ertype in ('Email', 'EmailThread', 'EmailPart', 'File', 'Image',
                            'sender', 'in_thread', 'reply_to', 'data_format'):
                 self.failUnless(ertype in schema, ertype)
@@ -420,8 +417,6 @@
                               email_version)
             self.assertEquals(self.execute('Any V WHERE X value V, X pkey "system.version.file"')[0][0],
                               file_version)
-            self.failUnless('email' in self.config.cubes())
-            self.failUnless('file' in self.config.cubes())
             # trick: overwrite self.maxeid to avoid deletion of just reintroduced
             #        types (and their associated tables!)
             self.maxeid = self.execute('Any MAX(X)')[0][0]
@@ -429,6 +424,38 @@
             # next test may fail complaining of missing tables
             self.commit()
 
+
+    def test_add_remove_cube_no_deps(self):
+        cubes = set(self.config.cubes())
+        schema = self.repo.schema
+        try:
+            try:
+                self.mh.cmd_remove_cube('email')
+                cubes.remove('email')
+                self.failIf('email' in self.config.cubes())
+                self.failUnless('file' in self.config.cubes())
+                for ertype in ('Email', 'EmailThread', 'EmailPart',
+                               'sender', 'in_thread', 'reply_to'):
+                    self.failIf(ertype in schema, ertype)
+            except :
+                import traceback
+                traceback.print_exc()
+                raise
+        finally:
+            self.mh.cmd_add_cube('email')
+            self.failUnless('email' in self.config.cubes())
+            # trick: overwrite self.maxeid to avoid deletion of just reintroduced
+            #        types (and their associated tables!)
+            self.maxeid = self.execute('Any MAX(X)')[0][0]
+            # why this commit is necessary is unclear to me (though without it
+            # next test may fail complaining of missing tables
+            self.commit()
+
+    def test_remove_dep_cube(self):
+        ex = self.assertRaises(ConfigurationError, self.mh.cmd_remove_cube, 'file')
+        self.assertEquals(str(ex), "can't remove cube file, used as a dependency")
+
+
     def test_set_state(self):
         user = self.session.user
         self.mh.set_state(user.eid, 'deactivated')