]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added a unit test for the "version_id" keyword argument, which passes based on previo...
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Apr 2006 22:01:35 +0000 (22:01 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 3 Apr 2006 22:01:35 +0000 (22:01 +0000)
CHANGES
test/objectstore.py

diff --git a/CHANGES b/CHANGES
index 4a5da956bad215b3d68edc87b8b67314aad39c26..fa3e27d3b3c13345efa6862084901dc312cfb1f4 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,10 @@
 0.1.6
+- added 'version_id' keyword argument to mapper. this keyword should reference a
+Column object with type Integer, preferably non-nullable, which will be used on
+the mapped table to track version numbers. this number is incremented on each
+save operation and is specifed in the UPDATE/DELETE conditions so that it
+factors into the returned row count, which results in a ConcurrencyError if the
+value received is not the expected count.
 - added 'entity_name' keyword argument to mapper. a mapper is now associated
 with a class via the class object as well as an optional entity_name parameter,
 which is a string defaulting to None. any number of primary mappers can be
index 97b7e817dcbaa89f224ce3cfa8191a769d866ba1..9166c5dea8ac064d6c9aefaf1fd9545068bce29b 100644 (file)
@@ -169,6 +169,60 @@ class SessionTest(AssertMixin):
         objectstore.clear()
         self.assert_(m.get(8).user_name == name2)
         self.assert_(m.get(7).user_name != name1)
+
+class VersioningTest(AssertMixin):
+    def setUpAll(self):
+        global version_table
+        version_table = Table('version_test', db,
+        Column('id', Integer, primary_key=True),
+        Column('version_id', Integer, nullable=False),
+        Column('value', String(40), nullable=False)
+        ).create()
+    def tearDownAll(self):
+        version_table.drop()
+    def tearDown(self):
+        version_table.delete().execute()
+        objectstore.clear()
+        clear_mappers()
+        
+    def testbasic(self):
+        class Foo(object):pass
+        assign_mapper(Foo, version_table, version_id_col=version_table.c.version_id)
+        f1 =Foo(value='f1')
+        f2 = Foo(value='f2')
+        objectstore.commit()
+        
+        f1.value='f1rev2'
+        objectstore.commit()
+        s = objectstore.Session()
+        f1_s = Foo.mapper.using(s).get(f1.id)
+        f1_s.value='f1rev3'
+        s.commit()
+
+        f1.value='f1rev3mine'
+        success = False
+        try:
+            # a concurrent session has modified this, should throw
+            # an exception
+            objectstore.commit()
+        except SQLAlchemyError:
+            success = True
+        assert success
+        
+        objectstore.clear()
+        f1 = Foo.mapper.get(f1.id)
+        f2 = Foo.mapper.get(f2.id)
+        
+        f1_s.value='f1rev4'
+        s.commit()
+    
+        objectstore.delete(f1, f2)
+        success = False
+        try:
+            objectstore.commit()
+        except SQLAlchemyError:
+            success = True
+        assert success
         
 class UnicodeTest(AssertMixin):
     def setUpAll(self):