Skip to content

Commit

Permalink
Drop DB
Browse files Browse the repository at this point in the history
  • Loading branch information
heynemann committed Aug 26, 2010
1 parent e68490f commit c09502b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions db_migrate/domain/db.py
Expand Up @@ -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.'''
Expand Down
8 changes: 7 additions & 1 deletion tests/functional/domain/test_db.py
Expand Up @@ -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()
Expand All @@ -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
13 changes: 13 additions & 0 deletions tests/unit/domain/test_db.py
Expand Up @@ -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():
Expand Down

0 comments on commit c09502b

Please sign in to comment.