From c09502b6a69671d542f8f4b9dcee17af6d844091 Mon Sep 17 00:00:00 2001 From: Bernardo Heynemann Date: Thu, 26 Aug 2010 08:54:56 -0300 Subject: [PATCH] Drop DB --- db_migrate/domain/db.py | 6 ++++++ tests/functional/domain/test_db.py | 8 +++++++- tests/unit/domain/test_db.py | 13 +++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/db_migrate/domain/db.py b/db_migrate/domain/db.py index c7daa04..6b60df0 100644 --- a/db_migrate/domain/db.py +++ b/db_migrate/domain/db.py @@ -82,6 +82,12 @@ def create_database(self): self.execute(sql, to_main_database=True) + def drop_database(self): + '''Drops the database with the config specified name.''' + sql = "DROP DATABASE IF EXISTS %s" % self.config.db + + self.execute(sql, to_main_database=True) + @property def connection_string(self): '''Returns the proper connection string according to config.''' diff --git a/tests/functional/domain/test_db.py b/tests/functional/domain/test_db.py index 65fe0d3..58e48e9 100644 --- a/tests/functional/domain/test_db.py +++ b/tests/functional/domain/test_db.py @@ -75,7 +75,7 @@ def test_can_scalar_query_command_in_main_database(): assert result == 1L -def test_can_create_database(): +def test_can_create_and_drop_database(): db = Db(config=NEW_DB_CONFIG) db.create_database() @@ -85,3 +85,9 @@ def test_can_create_database(): results = new_db.execute('show databases', to_main_database=True) dbs = [result[0] for result in results.fetchall()] assert 'db_migrate_test_database_2' in dbs + + db.drop_database() + + results = new_db.execute('show databases', to_main_database=True) + dbs = [result[0] for result in results.fetchall()] + assert 'db_migrate_test_database_2' not in dbs diff --git a/tests/unit/domain/test_db.py b/tests/unit/domain/test_db.py index 720fb5c..c73f144 100644 --- a/tests/unit/domain/test_db.py +++ b/tests/unit/domain/test_db.py @@ -140,6 +140,19 @@ def test_create_db(): db.create_database() +@with_fakes +@with_patched_object(Db, 'execute', Fake(callable=True)) +def test_drop_db(): + clear_expectations() + + config = fake_config() + + db = Db(config) + + Db.execute.with_args('DROP DATABASE IF EXISTS myDb', to_main_database=True) + + db.drop_database() + @with_fakes @with_patched_object(Db, 'connect', Fake(callable=True)) def test_execute_calls_connect_if_no_connection_done():