From a94dae7a01193f34ec2ec900af6aaa8c72d8c881 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 30 Jun 2015 11:46:12 -0400 Subject: [PATCH] Update tests and reqs for SQLA 1.0 Lift the requirements to support SQLAlchemy 1.0. Two tests were calling upon revised APIs and required adjustment. Change-Id: Ic91a91bb3c915027b522eace302f2ed074233294 --- migrate/changeset/__init__.py | 2 ++ migrate/changeset/util.py | 11 +++++++++++ migrate/tests/changeset/test_constraint.py | 3 ++- migrate/tests/versioning/test_database.py | 6 ++++-- requirements.txt | 2 +- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/migrate/changeset/__init__.py b/migrate/changeset/__init__.py index 7eb256a..507fa73 100644 --- a/migrate/changeset/__init__.py +++ b/migrate/changeset/__init__.py @@ -12,6 +12,8 @@ from sqlalchemy import __version__ as _sa_version _sa_version = tuple(int(re.match("\d+", x).group(0)) for x in _sa_version.split(".")) SQLA_07 = _sa_version >= (0, 7) SQLA_08 = _sa_version >= (0, 8) +SQLA_09 = _sa_version >= (0, 9) +SQLA_10 = _sa_version >= (1, 0) del re del _sa_version diff --git a/migrate/changeset/util.py b/migrate/changeset/util.py index 402870f..f8ecd81 100644 --- a/migrate/changeset/util.py +++ b/migrate/changeset/util.py @@ -1,3 +1,5 @@ +from migrate.changeset import SQLA_10 + """ Safe quoting method """ @@ -8,3 +10,12 @@ def safe_quote(obj): return obj.name.quote else: return obj.quote + + +def fk_column_names(constraint): + if SQLA_10: + return [ + constraint.columns[key].name for key in constraint.column_keys] + else: + return [ + element.parent.name for element in constraint.elements] diff --git a/migrate/tests/changeset/test_constraint.py b/migrate/tests/changeset/test_constraint.py index 1faf4cc..325b3c0 100644 --- a/migrate/tests/changeset/test_constraint.py +++ b/migrate/tests/changeset/test_constraint.py @@ -5,6 +5,7 @@ from sqlalchemy import * from sqlalchemy.util import * from sqlalchemy.exc import * +from migrate.changeset.util import fk_column_names from migrate.exceptions import * from migrate.changeset import * @@ -91,7 +92,7 @@ class TestConstraint(CommonTestConstraint): self.assertTrue(list(self.table.c.fkey.foreign_keys) is not []) else: self.assertTrue(self.table.c.fkey.foreign_keys._list is not []) - for key in fk.columns: + for key in fk_column_names(fk): self.assertEqual(key, self.table.c.fkey.name) self.assertEqual([e.column for e in fk.elements], [self.table.c.id]) self.assertEqual(list(fk.referenced), [self.table.c.id]) diff --git a/migrate/tests/versioning/test_database.py b/migrate/tests/versioning/test_database.py index 525385f..8291c6b 100644 --- a/migrate/tests/versioning/test_database.py +++ b/migrate/tests/versioning/test_database.py @@ -1,4 +1,4 @@ -from sqlalchemy import select +from sqlalchemy import select, text from migrate.tests import fixture class TestConnect(fixture.DB): @@ -8,4 +8,6 @@ class TestConnect(fixture.DB): def test_connect(self): """Connect to the database successfully""" # Connection is done in fixture.DB setup; make sure we can do stuff - select(['42'],bind=self.engine).execute() + self.engine.execute( + select([text('42')]) + ) diff --git a/requirements.txt b/requirements.txt index ee867b6..4d60d8b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,7 @@ pbr>=0.6,!=0.7,<1.0 # never put a cap on this, *ever*, sqla versions are handled via # tox, and if SQLA is capped it will only make it so we aren't testing # against all the versions we are compatible with. -SQLAlchemy>=0.7.8,!=0.9.5,<=0.9.99 +SQLAlchemy>=0.7.8,!=0.9.5,<=1.0.99 decorator six>=1.7.0 sqlparse