diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-07-30 10:06:53 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2016-07-30 10:06:53 -0400 |
commit | e467e899e126db2db7c25d533aee12d78c2dbdfb (patch) | |
tree | fe79069d57f597ebc5f0c0c76d752d536c93f6a3 /test/sql/test_constraints.py | |
parent | 5df226c2ab549ccf84f912110bf233f562d5eb32 (diff) | |
download | sqlalchemy-e467e899e126db2db7c25d533aee12d78c2dbdfb.tar.gz |
- Consoliate test/sql/test_constraint ConstraintAPITest
and test/sql/test_metadata IndexTest into
test/sql/test_metadata ConstraintTest
Change-Id: I7aeee9a1edbbd889200afc393695f73d5fbac3f3
Diffstat (limited to 'test/sql/test_constraints.py')
-rw-r--r-- | test/sql/test_constraints.py | 342 |
1 files changed, 0 insertions, 342 deletions
diff --git a/test/sql/test_constraints.py b/test/sql/test_constraints.py index 3e8021ebe..efd52ffb5 100644 --- a/test/sql/test_constraints.py +++ b/test/sql/test_constraints.py @@ -1150,345 +1150,3 @@ class ConstraintCompilationTest(fixtures.TestBase, AssertsCompiledSQL): ) -class ConstraintAPITest(fixtures.TestBase): - - def test_double_fk_usage_raises(self): - f = ForeignKey('b.id') - - Column('x', Integer, f) - assert_raises(exc.InvalidRequestError, Column, "y", Integer, f) - - def test_auto_append_constraint(self): - m = MetaData() - - t = Table('tbl', m, - Column('a', Integer), - Column('b', Integer) - ) - - t2 = Table('t2', m, - Column('a', Integer), - Column('b', Integer) - ) - - for c in ( - UniqueConstraint(t.c.a), - CheckConstraint(t.c.a > 5), - ForeignKeyConstraint([t.c.a], [t2.c.a]), - PrimaryKeyConstraint(t.c.a) - ): - assert c in t.constraints - t.append_constraint(c) - assert c in t.constraints - - c = Index('foo', t.c.a) - assert c in t.indexes - - def test_auto_append_lowercase_table(self): - t = table('t', column('a')) - t2 = table('t2', column('a')) - for c in ( - UniqueConstraint(t.c.a), - CheckConstraint(t.c.a > 5), - ForeignKeyConstraint([t.c.a], [t2.c.a]), - PrimaryKeyConstraint(t.c.a), - Index('foo', t.c.a) - ): - assert True - - def test_tometadata_ok(self): - m = MetaData() - - t = Table('tbl', m, - Column('a', Integer), - Column('b', Integer) - ) - - t2 = Table('t2', m, - Column('a', Integer), - Column('b', Integer) - ) - - UniqueConstraint(t.c.a) - CheckConstraint(t.c.a > 5) - ForeignKeyConstraint([t.c.a], [t2.c.a]) - PrimaryKeyConstraint(t.c.a) - - m2 = MetaData() - - t3 = t.tometadata(m2) - - eq_(len(t3.constraints), 4) - - for c in t3.constraints: - assert c.table is t3 - - def test_check_constraint_copy(self): - m = MetaData() - t = Table('tbl', m, - Column('a', Integer), - Column('b', Integer) - ) - ck = CheckConstraint(t.c.a > 5) - ck2 = ck.copy() - assert ck in t.constraints - assert ck2 not in t.constraints - - def test_ambig_check_constraint_auto_append(self): - m = MetaData() - - t = Table('tbl', m, - Column('a', Integer), - Column('b', Integer) - ) - - t2 = Table('t2', m, - Column('a', Integer), - Column('b', Integer) - ) - c = CheckConstraint(t.c.a > t2.c.b) - assert c not in t.constraints - assert c not in t2.constraints - - def test_auto_append_ck_on_col_attach_one(self): - m = MetaData() - - a = Column('a', Integer) - b = Column('b', Integer) - ck = CheckConstraint(a > b) - - t = Table('tbl', m, a, b) - assert ck in t.constraints - - def test_auto_append_ck_on_col_attach_two(self): - m = MetaData() - - a = Column('a', Integer) - b = Column('b', Integer) - c = Column('c', Integer) - ck = CheckConstraint(a > b + c) - - t = Table('tbl', m, a) - assert ck not in t.constraints - - t.append_column(b) - assert ck not in t.constraints - - t.append_column(c) - assert ck in t.constraints - - def test_auto_append_ck_on_col_attach_three(self): - m = MetaData() - - a = Column('a', Integer) - b = Column('b', Integer) - c = Column('c', Integer) - ck = CheckConstraint(a > b + c) - - t = Table('tbl', m, a) - assert ck not in t.constraints - - t.append_column(b) - assert ck not in t.constraints - - t2 = Table('t2', m) - t2.append_column(c) - - # two different tables, so CheckConstraint does nothing. - assert ck not in t.constraints - - def test_auto_append_uq_on_col_attach_one(self): - m = MetaData() - - a = Column('a', Integer) - b = Column('b', Integer) - uq = UniqueConstraint(a, b) - - t = Table('tbl', m, a, b) - assert uq in t.constraints - - def test_auto_append_uq_on_col_attach_two(self): - m = MetaData() - - a = Column('a', Integer) - b = Column('b', Integer) - c = Column('c', Integer) - uq = UniqueConstraint(a, b, c) - - t = Table('tbl', m, a) - assert uq not in t.constraints - - t.append_column(b) - assert uq not in t.constraints - - t.append_column(c) - assert uq in t.constraints - - def test_auto_append_uq_on_col_attach_three(self): - m = MetaData() - - a = Column('a', Integer) - b = Column('b', Integer) - c = Column('c', Integer) - uq = UniqueConstraint(a, b, c) - - t = Table('tbl', m, a) - assert uq not in t.constraints - - t.append_column(b) - assert uq not in t.constraints - - t2 = Table('t2', m) - - # two different tables, so UniqueConstraint raises - assert_raises_message( - exc.ArgumentError, - r"Column\(s\) 't2\.c' are not part of table 'tbl'\.", - t2.append_column, c - ) - - def test_auto_append_uq_on_col_attach_four(self): - """Test that a uniqueconstraint that names Column and string names - won't autoattach using deferred column attachment. - - """ - m = MetaData() - - a = Column('a', Integer) - b = Column('b', Integer) - c = Column('c', Integer) - uq = UniqueConstraint(a, 'b', 'c') - - t = Table('tbl', m, a) - assert uq not in t.constraints - - t.append_column(b) - assert uq not in t.constraints - - t.append_column(c) - - # we don't track events for previously unknown columns - # named 'c' to be attached - assert uq not in t.constraints - - t.append_constraint(uq) - - assert uq in t.constraints - - eq_( - [cn for cn in t.constraints if isinstance(cn, UniqueConstraint)], - [uq] - ) - - def test_auto_append_uq_on_col_attach_five(self): - """Test that a uniqueconstraint that names Column and string names - *will* autoattach if the table has all those names up front. - - """ - m = MetaData() - - a = Column('a', Integer) - b = Column('b', Integer) - c = Column('c', Integer) - - t = Table('tbl', m, a, c, b) - - uq = UniqueConstraint(a, 'b', 'c') - - assert uq in t.constraints - - t.append_constraint(uq) - - assert uq in t.constraints - - eq_( - [cn for cn in t.constraints if isinstance(cn, UniqueConstraint)], - [uq] - ) - - def test_index_asserts_cols_standalone(self): - metadata = MetaData() - - t1 = Table('t1', metadata, - Column('x', Integer) - ) - t2 = Table('t2', metadata, - Column('y', Integer) - ) - assert_raises_message( - exc.ArgumentError, - r"Column\(s\) 't2.y' are not part of table 't1'.", - Index, - "bar", t1.c.x, t2.c.y - ) - - def test_index_asserts_cols_inline(self): - metadata = MetaData() - - t1 = Table('t1', metadata, - Column('x', Integer) - ) - assert_raises_message( - exc.ArgumentError, - "Index 'bar' is against table 't1', and " - "cannot be associated with table 't2'.", - Table, 't2', metadata, - Column('y', Integer), - Index('bar', t1.c.x) - ) - - def test_raise_index_nonexistent_name(self): - m = MetaData() - # the KeyError isn't ideal here, a nicer message - # perhaps - assert_raises( - KeyError, - Table, 't', m, Column('x', Integer), Index("foo", "q") - ) - - def test_raise_not_a_column(self): - assert_raises( - exc.ArgumentError, - Index, "foo", 5 - ) - - def test_raise_expr_no_column(self): - idx = Index('foo', func.lower(5)) - - assert_raises_message( - exc.CompileError, - "Index 'foo' is not associated with any table.", - schema.CreateIndex(idx).compile, dialect=testing.db.dialect - ) - assert_raises_message( - exc.CompileError, - "Index 'foo' is not associated with any table.", - schema.CreateIndex(idx).compile - ) - - def test_no_warning_w_no_columns(self): - idx = Index(name="foo") - - assert_raises_message( - exc.CompileError, - "Index 'foo' is not associated with any table.", - schema.CreateIndex(idx).compile, dialect=testing.db.dialect - ) - assert_raises_message( - exc.CompileError, - "Index 'foo' is not associated with any table.", - schema.CreateIndex(idx).compile - ) - - def test_raise_clauseelement_not_a_column(self): - m = MetaData() - t2 = Table('t2', m, Column('x', Integer)) - - class SomeClass(object): - - def __clause_element__(self): - return t2 - assert_raises( - exc.ArgumentError, - Index, "foo", SomeClass() - ) |