]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added unit tests illustrating current workaround for assignmapper method name/collect...
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 24 Jan 2007 22:43:25 +0000 (22:43 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 24 Jan 2007 22:43:25 +0000 (22:43 +0000)
test/ext/alltests.py
test/ext/assignmapper.py [new file with mode: 0644]

index f1c631ba43df74c9848eba878c9ccfbccca48d07..e13f5472f98b1a6ba7f1dbd35d9f592a7e8494fc 100644 (file)
@@ -2,7 +2,7 @@ import testbase
 import unittest, doctest
 
 def suite():
-    unittest_modules = ['ext.activemapper', 'ext.selectresults']
+    unittest_modules = ['ext.activemapper', 'ext.selectresults', 'ext.assignmapper']
     doctest_modules = ['sqlalchemy.ext.sqlsoup']
 
     alltests = unittest.TestSuite()
diff --git a/test/ext/assignmapper.py b/test/ext/assignmapper.py
new file mode 100644 (file)
index 0000000..d42a809
--- /dev/null
@@ -0,0 +1,51 @@
+from testbase import PersistTest, AssertMixin
+import testbase
+
+from sqlalchemy import *
+
+from sqlalchemy.ext.assignmapper import assign_mapper
+from sqlalchemy.ext.sessioncontext import SessionContext
+
+class OverrideAttributesTest(PersistTest):
+    def setUpAll(self):
+        global metadata, table, table2
+        metadata = BoundMetaData(testbase.db)
+        table = Table('sometable', metadata, 
+            Column('id', Integer, primary_key=True),
+            Column('data', String(30)))
+        table2 = Table('someothertable', metadata, 
+            Column('id', Integer, primary_key=True),
+            Column('someid', None, ForeignKey('sometable.id'))
+            )
+        metadata.create_all()
+    def tearDownAll(self):
+        metadata.drop_all()
+    def tearDown(self):
+        clear_mappers()
+    def setUp(self):
+        pass
+    def test_override_attributes(self):
+        class SomeObject(object):pass
+        class SomeOtherObject(object):pass
+        
+        ctx = SessionContext(create_session)
+        assign_mapper(ctx, SomeObject, table, properties={
+            # this is the current workaround for class attribute name/collection collision: specify collection_class
+            # explicitly.   when we do away with class attributes specifying collection classes, this wont be
+            # needed anymore.
+            'options':relation(SomeOtherObject, collection_class=list)
+        })
+        assign_mapper(ctx, SomeOtherObject, table2)
+        class_mapper(SomeObject)
+        s = SomeObject()
+        s.id = 1
+        s.data = 'hello'
+        sso = SomeOtherObject()
+        s.options.append(sso)
+        ctx.current.flush()
+        ctx.current.clear()
+        
+        assert SomeObject.get_by(id=s.id).options[0].id == sso.id
+        
+if __name__ == '__main__':
+    testbase.main()
\ No newline at end of file