diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-07-24 10:10:28 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-07-24 10:10:28 -0400 |
| commit | 8e0618aa650c43b483dbae443ddca94fcdd5b945 (patch) | |
| tree | 5afa12ff20e2c05aae2f379beb26832077987254 /test/orm/test_versioning.py | |
| parent | ca9029ca9830573c4a5618e5dc01347576d50eb4 (diff) | |
| download | sqlalchemy-8e0618aa650c43b483dbae443ddca94fcdd5b945.tar.gz | |
- The value of version_id_col can be changed
manually, and this will result in an UPDATE
of the row. Versioned UPDATEs and DELETEs
now use the "committed" value of the
version_id_col in the WHERE clause and
not the pending changed value. The
version generator is also bypassed if
manual changes are present on the attribute.
[ticket:1857]
- ensure before_update/after_update called on parent
for collection change
Diffstat (limited to 'test/orm/test_versioning.py')
| -rw-r--r-- | test/orm/test_versioning.py | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/test/orm/test_versioning.py b/test/orm/test_versioning.py index ccb1c0177..783c30ab3 100644 --- a/test/orm/test_versioning.py +++ b/test/orm/test_versioning.py @@ -108,6 +108,40 @@ class VersioningTest(_base.MappedTest): s1.commit() @testing.emits_warning(r'.*does not support updated rowcount') + @testing.resolve_artifact_names + def test_bump_version(self): + """test that version number can be bumped. + + Ensures that the UPDATE or DELETE is against the + last committed version of version_id_col, not the modified + state. + + """ + mapper(Foo, version_table, + version_id_col=version_table.c.version_id) + + s1 = sessionmaker()() + f1 = Foo(value='f1') + s1.add(f1) + s1.commit() + eq_(f1.version_id, 1) + f1.version_id = 2 + s1.commit() + eq_(f1.version_id, 2) + + # skip an id, test that history + # is honored + f1.version_id = 4 + f1.value = "something new" + s1.commit() + eq_(f1.version_id, 4) + + f1.version_id = 5 + s1.delete(f1) + s1.commit() + eq_(s1.query(Foo).count(), 0) + + @testing.emits_warning(r'.*does not support updated rowcount') @engines.close_open_connections @testing.resolve_artifact_names def test_versioncheck(self): @@ -236,7 +270,7 @@ class RowSwitchTest(_base.MappedTest): assert P.c.property.strategy.use_get session = sessionmaker()() - session.add(P(id=1, data='P version 1')) + session.add(P(id='P1', data='P version 1')) session.commit() session.close() @@ -298,7 +332,7 @@ class AlternateGeneratorTest(_base.MappedTest): assert P.c.property.strategy.use_get session = sessionmaker()() - session.add(P(id=1, data='P version 1')) + session.add(P(id='P1', data='P version 1')) session.commit() session.close() @@ -314,8 +348,11 @@ class AlternateGeneratorTest(_base.MappedTest): def test_child_row_switch_two(self): Session = sessionmaker() + # TODO: not sure this test is + # testing exactly what its looking for + sess1 = Session() - sess1.add(P(id=1, data='P version 1')) + sess1.add(P(id='P1', data='P version 1')) sess1.commit() sess1.close() @@ -327,6 +364,7 @@ class AlternateGeneratorTest(_base.MappedTest): sess1.delete(p1) sess1.commit() + # this can be removed and it still passes sess1.add(P(id='P1', data='P version 2')) sess1.commit() |
