diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-30 11:21:19 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-30 11:21:43 -0400 |
commit | 6ece305692399db8266fb028a9fe5f8a1af0295b (patch) | |
tree | a3979c1291fac9e962bf522537c148eff9d48453 /test/orm/inheritance/test_basic.py | |
parent | 3b24ccaf28fd85a6e54aa813fde8b3677253f67f (diff) | |
download | sqlalchemy-6ece305692399db8266fb028a9fe5f8a1af0295b.tar.gz |
add better tests for [ticket:2750]
Diffstat (limited to 'test/orm/inheritance/test_basic.py')
-rw-r--r-- | test/orm/inheritance/test_basic.py | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/test/orm/inheritance/test_basic.py b/test/orm/inheritance/test_basic.py index 3165237b2..99a008436 100644 --- a/test/orm/inheritance/test_basic.py +++ b/test/orm/inheritance/test_basic.py @@ -616,7 +616,10 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest): assert isinstance(sess.query(A).first(), C) - def test_assignment(self): + def test_valid_assignment_upwards(self): + """test that we can assign 'd' to a B, since B/D + both involve the same set of tables. + """ D, B = self.classes.D, self.classes.B sess = Session() @@ -627,8 +630,11 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest): sess.close() assert isinstance(sess.query(B).first(), D) - def test_invalid_assignment(self): - C, B = self.classes.C, self.classes.B + def test_invalid_assignment_downwards(self): + """test that we warn on assign of 'b' to a C, since this adds + a row to the C table we'd never load. + """ + C = self.classes.C sess = Session() c1 = C() @@ -642,6 +648,42 @@ class PolymorphicAttributeManagementTest(fixtures.MappedTest): sess.flush ) + def test_invalid_assignment_upwards(self): + """test that we warn on assign of 'c' to a B, since we will have a + "C" row that has no joined row, which will cause object + deleted errors. + """ + B = self.classes.B + + sess = Session() + b1 = B() + b1.class_name = 'c' + sess.add(b1) + assert_raises_message( + sa_exc.SAWarning, + "Flushing object %s with incompatible " + "polymorphic identity 'c'; the object may not " + "refresh and/or load correctly" % instance_str(b1), + sess.flush + ) + + def test_entirely_oob_assignment(self): + """test warn on an unknown polymorphic identity. + """ + B = self.classes.B + + sess = Session() + b1 = B() + b1.class_name = 'xyz' + sess.add(b1) + assert_raises_message( + sa_exc.SAWarning, + "Flushing object %s with incompatible " + "polymorphic identity 'xyz'; the object may not " + "refresh and/or load correctly" % instance_str(b1), + sess.flush + ) + class CascadeTest(fixtures.MappedTest): """that cascades on polymorphic relationships continue cascading along the path of the instance's mapper, not |