]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
add simple tests for new name argument for Table.tometadata()
authorndparker <ndparker@users.noreply.github.com>
Fri, 3 Oct 2014 22:51:01 +0000 (00:51 +0200)
committerndparker <ndparker@users.noreply.github.com>
Fri, 3 Oct 2014 22:51:01 +0000 (00:51 +0200)
test/sql/test_metadata.py

index 304e2cc5f09a1101ba4c2cc9ab4851cbea46971d..0e845d5553b1ff11235e7e8a8a98f18079b0d2ea 100644 (file)
@@ -678,6 +678,50 @@ class ToMetaDataTest(fixtures.TestBase, ComparesTables):
         eq_(str(table_c.join(table2_c).onclause),
             'myschema.mytable.myid = myschema.othertable.myid')
 
+    def test_change_name_retain_metadata(self):
+        meta = MetaData()
+
+        table = Table('mytable', meta,
+                      Column('myid', Integer, primary_key=True),
+                      Column('name', String(40), nullable=True),
+                      Column('description', String(30),
+                             CheckConstraint("description='hi'")),
+                      UniqueConstraint('name'),
+                      schema='myschema',
+                      )
+
+        table2 = table.tometadata(table.metadata, name='newtable')
+        table3 = table.tometadata(table.metadata, schema='newschema',
+                                  name='newtable')
+
+        assert table.metadata is table2.metadata
+        assert table.metadata is table3.metadata
+        eq_((table.name, table2.name, table3.name),
+            ('mytable', 'newtable', 'newtable'))
+        eq_((table.key, table2.key, table3.key),
+            ('myschema.mytable', 'myschema.newtable', 'newschema.newtable'))
+
+    def test_change_name_change_metadata(self):
+        meta = MetaData()
+        meta2 = MetaData()
+
+        table = Table('mytable', meta,
+                      Column('myid', Integer, primary_key=True),
+                      Column('name', String(40), nullable=True),
+                      Column('description', String(30),
+                             CheckConstraint("description='hi'")),
+                      UniqueConstraint('name'),
+                      schema='myschema',
+                      )
+
+        table2 = table.tometadata(meta2, name='newtable')
+
+        assert table.metadata is not table2.metadata
+        eq_((table.name, table2.name),
+            ('mytable', 'newtable'))
+        eq_((table.key, table2.key),
+            ('myschema.mytable', 'myschema.newtable'))
+
     def _assert_fk(self, t2, schema, expected, referred_schema_fn=None):
         m2 = MetaData()
         existing_schema = t2.schema