# HG changeset patch # User cmlenz # Date 1126547295 0 # Node ID bd6234ed6ac53ee60f3419939c032949e50ed5b4 # Parent 8dbddcd0ef004d52e51c0bfe117b2becb4eed225 Allow deletion of build configurations from the web interface. Closes #27. diff --git a/bitten/model.py b/bitten/model.py --- a/bitten/model.py +++ b/bitten/model.py @@ -41,6 +41,29 @@ exists = property(fget=lambda self: self._old_name is not None) + def delete(self, db=None): + """Remove a build configuration and all dependent objects from the + database.""" + assert self.exists, 'Cannot delete non-existing configuration' + if not db: + db = self.env.get_db_cnx() + handle_ta = True + else: + handle_ta = False + + for platform in TargetPlatform.select(self.env, self.name, db=db): + platform.delete(db=db) + + for build in Build.select(self.env, config=self.name, db=db): + build.delete(db=db) + + cursor = db.cursor() + cursor.execute("DELETE FROM bitten_config WHERE name=%s", (self.name,)) + + if handle_ta: + db.commit() + self._old_name = None + def insert(self, db=None): """Insert a new configuration into the database.""" assert not self.exists, 'Cannot insert existing configuration' @@ -340,8 +363,6 @@ else: handle_ta = False - assert self.status == self.PENDING, 'Only pending builds can be deleted' - for step in BuildStep.select(self.env, build=self.id): step.delete(db=db) diff --git a/bitten/tests/model.py b/bitten/tests/model.py --- a/bitten/tests/model.py +++ b/bitten/tests/model.py @@ -10,7 +10,8 @@ import unittest from trac.test import EnvironmentStub -from bitten.model import BuildConfig, TargetPlatform, Build, BuildStep, BuildLog +from bitten.model import BuildConfig, TargetPlatform, Build, BuildStep, \ + BuildLog, schema class BuildConfigTestCase(unittest.TestCase): @@ -19,7 +20,7 @@ self.env = EnvironmentStub() db = self.env.get_db_cnx() cursor = db.cursor() - for table in BuildConfig._schema: + for table in schema: for stmt in db.to_sql(table): cursor.execute(stmt) db.commit() @@ -87,7 +88,7 @@ cursor.fetchone()) self.assertEqual(None, cursor.fetchone()) - def test_config_update_name(self): + def test_update_name(self): db = self.env.get_db_cnx() cursor = db.cursor() cursor.execute("INSERT INTO bitten_config (name,path,label,active) " @@ -114,6 +115,23 @@ config.name = None self.assertRaises(AssertionError, config.update) + def test_delete(self): + db = self.env.get_db_cnx() + cursor = db.cursor() + cursor.execute("INSERT INTO bitten_config (name,path,label,active) " + "VALUES (%s,%s,%s,%s)", ('test', 'trunk', 'Test', 0)) + + config = BuildConfig.fetch(self.env, 'test') + config.delete() + self.assertEqual(False, config.exists) + + cursor.execute("SELECT * FROM bitten_config WHERE name=%s", ('test',)) + self.assertEqual(None, cursor.fetchone()) + + def test_delete_non_existing(self): + config = BuildConfig(self.env, 'test') + self.assertRaises(AssertionError, config.delete) + class TargetPlatformTestCase(unittest.TestCase): diff --git a/bitten/trac_ext/templates/bitten_config.cs b/bitten/trac_ext/templates/bitten_config.cs --- a/bitten/trac_ext/templates/bitten_config.cs +++ b/bitten/trac_ext/templates/bitten_config.cs @@ -77,6 +77,16 @@ +
Are you sure you want to delete the build configuration "?
+This will also delete all builds performed for that configuration.
+