summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/testing
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
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')
-rw-r--r--lib/sqlalchemy/testing/plugin/noseplugin.py31
-rw-r--r--lib/sqlalchemy/testing/suite/test_reflection.py5
2 files changed, 22 insertions, 14 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()
diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py
index a02ee479e..6d36e4e56 100644
--- a/lib/sqlalchemy/testing/suite/test_reflection.py
+++ b/lib/sqlalchemy/testing/suite/test_reflection.py
@@ -116,7 +116,7 @@ class ComponentReflectionTest(fixtures.TablesTest):
)
cls.define_index(metadata, users)
- cls.define_views(metadata, schema=None)
+ cls.define_views(metadata, schema)
@classmethod
def define_index(cls, metadata, users):
@@ -131,6 +131,7 @@ class ComponentReflectionTest(fixtures.TablesTest):
view_name = fullname + '_v'
query = "CREATE VIEW %s AS SELECT * FROM %s" % (
view_name, fullname)
+
event.listen(
metadata,
"after_create",
@@ -173,7 +174,7 @@ class ComponentReflectionTest(fixtures.TablesTest):
table_names = insp.get_table_names(schema,
order_by=order_by)
if order_by == 'foreign_key':
- answer = ['dingalings', 'email_addresses', 'users']
+ answer = ['users', 'email_addresses', 'dingalings']
eq_(table_names, answer)
else:
answer = ['dingalings', 'email_addresses', 'users']