summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing/plugin/noseplugin.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-10-01 01:59:59 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2012-10-01 01:59:59 -0400
commit0bb5a9eab829f9a4cfda3c37cdf2202d84e55f3f (patch)
tree2e7847e098ac547b5907c6650e219e9b0a65236e /lib/sqlalchemy/testing/plugin/noseplugin.py
parenteaa15b3c70020b96aebd2e05651eb18226ff4ee3 (diff)
downloadsqlalchemy-0bb5a9eab829f9a4cfda3c37cdf2202d84e55f3f.tar.gz
- fix the fixture here that wasn't creating consistently
- rewrite --dropfirst to be more industrial strength, includes views - fix order_by="foreign_key" to maintain the same ordering as metadata.sorted_tables. Not ideal that this was the other way throughout 0.7 but this is still a little-used method, in contrast to metadata.sorted_tables.
Diffstat (limited to 'lib/sqlalchemy/testing/plugin/noseplugin.py')
-rw-r--r--lib/sqlalchemy/testing/plugin/noseplugin.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/lib/sqlalchemy/testing/plugin/noseplugin.py b/lib/sqlalchemy/testing/plugin/noseplugin.py
index cf132198f..1034749e7 100644
--- a/lib/sqlalchemy/testing/plugin/noseplugin.py
+++ b/lib/sqlalchemy/testing/plugin/noseplugin.py
@@ -148,22 +148,29 @@ def _create_testing_engine(options, file_config):
@post
def _prep_testing_database(options, file_config):
from sqlalchemy.testing import engines
- from sqlalchemy import schema
+ from sqlalchemy import schema, inspect
# also create alt schemas etc. here?
if options.dropfirst:
e = engines.utf8_engine()
- existing = e.table_names()
- if existing:
- print "Dropping existing tables in database: " + db_url
- try:
- print "Tables: %s" % ', '.join(existing)
- except:
- pass
- print "Abort within 5 seconds..."
- time.sleep(5)
- md = schema.MetaData(e, reflect=True)
- md.drop_all()
+ inspector = inspect(e)
+
+ for vname in inspector.get_view_names():
+ e.execute(schema._DropView(schema.Table(vname, schema.MetaData())))
+
+ for vname in inspector.get_view_names(schema="test_schema"):
+ e.execute(schema._DropView(
+ schema.Table(vname,
+ schema.MetaData(), schema="test_schema")))
+
+ for tname in reversed(inspector.get_table_names(order_by="foreign_key")):
+ e.execute(schema.DropTable(schema.Table(tname, schema.MetaData())))
+
+ for tname in reversed(inspector.get_table_names(
+ order_by="foreign_key", schema="test_schema")):
+ e.execute(schema.DropTable(
+ schema.Table(tname, schema.MetaData(), schema="test_schema")))
+
e.dispose()