From 4ad4e9fccbb263ac2a0e6bf5f84526b2dee19ece Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 6 Feb 2013 16:36:35 -0500 Subject: [PATCH] - cleanup HasSequence and move it to test_sequences --- .../testing/suite/test_reflection.py | 42 +------------- lib/sqlalchemy/testing/suite/test_sequence.py | 58 ++++++++++++++++++- 2 files changed, 58 insertions(+), 42 deletions(-) diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index b9894347ad..89e233295e 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -3,7 +3,6 @@ from __future__ import with_statement import sqlalchemy as sa from sqlalchemy import exc as sa_exc from sqlalchemy import types as sql_types -from sqlalchemy import schema from sqlalchemy import inspect from sqlalchemy import MetaData, Integer, String from sqlalchemy.engine.reflection import Inspector @@ -33,45 +32,6 @@ class HasTableTest(fixtures.TablesTest): assert not config.db.dialect.has_table(conn, "nonexistent_table") -class HasSequenceTest(fixtures.TestBase): - __requires__ = 'sequences', - - def test_has_sequence(self): - metadata = MetaData() - Table('users', metadata, Column('user_id', sa.Integer, - sa.Sequence('user_id_seq'), primary_key=True), - Column('user_name', sa.String(40))) - metadata.create_all(bind=testing.db) - try: - eq_(testing.db.dialect.has_sequence(testing.db, - 'user_id_seq'), True) - finally: - metadata.drop_all(bind=testing.db) - eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'), - False) - - @testing.requires.schemas - def test_has_sequence_schema(self): - test_schema = 'test_schema' - s1 = sa.Sequence('user_id_seq', schema=test_schema) - s2 = sa.Sequence('user_id_seq') - testing.db.execute(schema.CreateSequence(s1)) - testing.db.execute(schema.CreateSequence(s2)) - eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq', - schema=test_schema), True) - eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'), - True) - testing.db.execute(schema.DropSequence(s1)) - eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq', - schema=test_schema), False) - eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'), - True) - testing.db.execute(schema.DropSequence(s2)) - eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq', - schema=test_schema), False) - eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'), - False) - class ComponentReflectionTest(fixtures.TablesTest): run_inserts = run_deletes = None @@ -427,4 +387,4 @@ class ComponentReflectionTest(fixtures.TablesTest): self._test_get_table_oid('users', schema='test_schema') -__all__ = ('ComponentReflectionTest', 'HasSequenceTest', 'HasTableTest') +__all__ = ('ComponentReflectionTest', 'HasTableTest') diff --git a/lib/sqlalchemy/testing/suite/test_sequence.py b/lib/sqlalchemy/testing/suite/test_sequence.py index 366d509cc3..6c6ba57958 100644 --- a/lib/sqlalchemy/testing/suite/test_sequence.py +++ b/lib/sqlalchemy/testing/suite/test_sequence.py @@ -1,8 +1,9 @@ from .. import fixtures, config from ..config import requirements from ..assertions import eq_ +from ... import testing -from sqlalchemy import Integer, String, Sequence +from ... import Integer, String, Sequence, schema from ..schema import Table, Column @@ -68,3 +69,58 @@ class SequenceTest(fixtures.TablesTest): (1, "some data") ) + +class HasSequenceTest(fixtures.TestBase): + __requires__ = 'sequences', + + def test_has_sequence(self): + s1 = Sequence('user_id_seq') + testing.db.execute(schema.CreateSequence(s1)) + try: + eq_(testing.db.dialect.has_sequence(testing.db, + 'user_id_seq'), True) + finally: + testing.db.execute(schema.DropSequence(s1)) + + @testing.requires.schemas + def test_has_sequence_schema(self): + s1 = Sequence('user_id_seq', schema="test_schema") + testing.db.execute(schema.CreateSequence(s1)) + try: + eq_(testing.db.dialect.has_sequence(testing.db, + 'user_id_seq', schema="test_schema"), True) + finally: + testing.db.execute(schema.DropSequence(s1)) + + def test_has_sequence_neg(self): + eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'), + False) + + @testing.requires.schemas + def test_has_sequence_schemas_neg(self): + eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq', + schema="test_schema"), + False) + + @testing.requires.schemas + def test_has_sequence_default_not_in_remote(self): + s1 = Sequence('user_id_seq') + testing.db.execute(schema.CreateSequence(s1)) + try: + eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq', + schema="test_schema"), + False) + finally: + testing.db.execute(schema.DropSequence(s1)) + + @testing.requires.schemas + def test_has_sequence_remote_not_in_default(self): + s1 = Sequence('user_id_seq', schema="test_schema") + testing.db.execute(schema.CreateSequence(s1)) + try: + eq_(testing.db.dialect.has_sequence(testing.db, 'user_id_seq'), + False) + finally: + testing.db.execute(schema.DropSequence(s1)) + + -- 2.47.2