diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-03-07 12:53:00 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-03-07 16:24:18 -0500 |
| commit | c04870ba7b8098c7d408ad66f60efe7229496fde (patch) | |
| tree | 48ce6b3cbb8225f85499e54dc92e7d58684812f7 /test/dialect/postgresql | |
| parent | 9e627159733da48e2fd2d25de93589eb079a75f4 (diff) | |
| download | sqlalchemy-c04870ba7b8098c7d408ad66f60efe7229496fde.tar.gz | |
Allow SchemaType and Variant to work together
Added support for the :class:`.Variant` and the :class:`.SchemaType`
objects to be compatible with each other. That is, a variant
can be created against a type like :class:`.Enum`, and the instructions
to create constraints and/or database-specific type objects will
propagate correctly as per the variant's dialect mapping.
Also added testing for some potential double-event scenarios
on TypeDecorator but it seems usually this doesn't occur.
Change-Id: I4a7e7c26b4133cd14e870f5bc34a1b2f0f19a14a
Fixes: #2892
Diffstat (limited to 'test/dialect/postgresql')
| -rw-r--r-- | test/dialect/postgresql/test_types.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index 3f2f6db3f..807eeb60c 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -523,6 +523,77 @@ class EnumTest(fixtures.TestBase, AssertsExecutionResults): "twoHITHERE" ) + @testing.provide_metadata + def test_generic_w_pg_variant(self): + some_table = Table( + 'some_table', self.metadata, + Column( + 'data', + Enum( + "one", "two", "three", + native_enum=True # make sure this is True because + # it should *not* take effect due to + # the variant + ).with_variant( + postgresql.ENUM("four", "five", "six", name="my_enum"), + "postgresql" + ) + ) + ) + + with testing.db.begin() as conn: + assert 'my_enum' not in [ + e['name'] for e in inspect(conn).get_enums()] + + self.metadata.create_all(conn) + + assert 'my_enum' in [ + e['name'] for e in inspect(conn).get_enums()] + + conn.execute( + some_table.insert(), {"data": "five"} + ) + + self.metadata.drop_all(conn) + + assert 'my_enum' not in [ + e['name'] for e in inspect(conn).get_enums()] + + @testing.provide_metadata + def test_generic_w_some_other_variant(self): + some_table = Table( + 'some_table', self.metadata, + Column( + 'data', + Enum( + "one", "two", "three", + name="my_enum", + native_enum=True + ).with_variant( + Enum("four", "five", "six"), + "mysql" + ) + ) + ) + + with testing.db.begin() as conn: + assert 'my_enum' not in [ + e['name'] for e in inspect(conn).get_enums()] + + self.metadata.create_all(conn) + + assert 'my_enum' in [ + e['name'] for e in inspect(conn).get_enums()] + + conn.execute( + some_table.insert(), {"data": "two"} + ) + + self.metadata.drop_all(conn) + + assert 'my_enum' not in [ + e['name'] for e in inspect(conn).get_enums()] + class OIDTest(fixtures.TestBase): __only_on__ = 'postgresql' |
