]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- moved unicode schema ORM tests to unitofwork.py tests. mostly
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 15 Aug 2007 16:48:57 +0000 (16:48 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 15 Aug 2007 16:48:57 +0000 (16:48 +0000)
is to test mappers so limited DB support (really hard to get these unicode schemas
to work...)
- fixed [ticket:739]

lib/sqlalchemy/orm/mapper.py
test/orm/fixtures.py
test/orm/unitofwork.py
test/sql/unicode.py

index 3870852d2aca20c9a8ec92c768a5a897140fca3c..86e5d3387c95c7db03e3f6137275211bfa498c2d 100644 (file)
@@ -1561,7 +1561,7 @@ class Mapper(object):
             params = {}
             for c in param_names:
                 params[c.name] = self.get_attr_by_column(instance, c)
-            row = selectcontext.session.connection(self).execute(statement, **params).fetchone()
+            row = selectcontext.session.connection(self).execute(statement, params).fetchone()
             self.populate_instance(selectcontext, instance, row, isnew=False, instancekey=identitykey, ispostselect=True)
 
         return post_execute
index d3d95a6b53ce6be7180de21ef88ce527d1a7f66f..33e0a419be093c524c9fd7d4370b8c3dd23821c9 100644 (file)
@@ -7,7 +7,12 @@ class Base(object):
     def __init__(self, **kwargs):
         for k in kwargs:
             setattr(self, k, kwargs[k])
-            
+    
+    def __repr__(self):
+        return "%s(%s)" % (
+            (self.__class__.__name__), 
+            ','.join(["%s=%s" % (key, repr(getattr(self, key))) for key in self.__dict__ if not key.startswith('_')])
+        )
     def __ne__(self, other):
         return not self.__eq__(other)
         
@@ -17,13 +22,14 @@ class Base(object):
         only look at attributes that are present on the source object.
         
         """
-        
+        print "WE ARE IN EQ"
         if self in _recursion_stack:
             return True
         _recursion_stack.add(self)
         try:
             # use __dict__ to avoid instrumented properties
             for attr in self.__dict__.keys():
+                print "ATTR", attr
                 if attr[0] == '_':
                     continue
                 value = getattr(self, attr)
@@ -42,6 +48,7 @@ class Base(object):
                         continue
                 else:
                     if value is not None:
+                        print "KEY", attr, "COMPARING", value, "TO", getattr(other, attr, None)
                         if value != getattr(other, attr, None):
                             return False
             else:
index 0a7df2a36ff75824422444246a192e14be4473f0..41400a333f6f82015709a06d38bfe538b01cdf59 100644 (file)
@@ -1,3 +1,4 @@
+# coding: utf-8
 import testbase
 import pickleable
 from sqlalchemy import *
@@ -5,6 +6,7 @@ from sqlalchemy.orm import *
 from testlib import *
 from testlib.tables import *
 from testlib import tables
+import fixtures
 
 """tests unitofwork operations"""
 
@@ -178,6 +180,71 @@ class UnicodeTest(ORMTest):
         t1 = Session.query(Test).get_by(id=t1.id)
         assert len(t1.t2s) == 2
 
+class UnicodeSchemaTest(ORMTest):
+    @testing.supported('sqlite', 'postgres')
+    def define_tables(self, metadata):
+        global t1, t2, t3
+
+        #unicode_bind = utf8_engine()
+
+        t1 = Table('unitable1', metadata,
+            Column(u'méil', Integer, primary_key=True, key='a'),
+            Column(u'\u6e2c\u8a66', Integer, key='b'),
+            Column('type',  String(20)),
+            test_needs_fk=True,
+            )
+        t2 = Table(u'Unitéble2', metadata,
+            Column(u'méil', Integer, primary_key=True, key="cc"),
+            Column(u'\u6e2c\u8a66', Integer, ForeignKey(u'unitable1.a'), key="d"),
+           Column(u'\u6e2c\u8a66_2', Integer, key="e"),
+                  test_needs_fk=True,
+            )
+        
+    @testing.supported('sqlite', 'postgres')
+    def test_mapping(self):
+        class A(fixtures.Base):pass
+        class B(fixtures.Base):pass
+
+        mapper(A, t1, properties={
+            't2s':relation(B),
+        })
+        mapper(B, t2)
+        a1 = A()
+        b1 = B()
+        a1.t2s.append(b1)
+        Session.flush()
+        Session.clear()
+        new_a1 = Session.query(A).filter(t1.c.a == a1.a).one()
+        assert new_a1.a == a1.a
+        assert new_a1.t2s[0].d == b1.d
+        Session.clear()
+
+        new_a1 = Session.query(A).options(eagerload('t2s')).filter(t1.c.a == a1.a).one()
+        assert new_a1.a == a1.a
+        assert new_a1.t2s[0].d == b1.d
+        Session.clear()
+
+        new_a1 = Session.query(A).filter(A.a == a1.a).one()
+        assert new_a1.a == a1.a
+        assert new_a1.t2s[0].d == b1.d
+        Session.clear()
+
+    @testing.supported('sqlite', 'postgres')
+    def test_inheritance_mapping(self):
+        class A(fixtures.Base):pass
+        class B(A):pass
+        mapper(A, t1, polymorphic_on=t1.c.type, polymorphic_identity='a')
+        mapper(B, t2, inherits=A, polymorphic_identity='b')
+        a1 = A(b=5)
+        b1 = B(e=7)
+
+        Session.flush()
+        Session.clear()
+        # TODO: somehow, not assigning to "l" first
+        # breaks the comparison ?????
+        l = Session.query(A).all()
+        assert [A(b=5), B(e=7)] == l
+    
 class MutableTypesTest(ORMTest):
     def define_tables(self, metadata):
         global table
index 19e78ed59f9110d544ddb86a3c4766982daaa2a0..8174ab8b6815d34798e650163147ad89d67e97d9 100644 (file)
@@ -3,7 +3,6 @@
 
 import testbase
 from sqlalchemy import *
-from sqlalchemy.orm import mapper, relation, create_session, eagerload
 from testlib import *
 from testlib.engines import utf8_engine
 
@@ -104,40 +103,7 @@ class UnicodeSchemaTest(PersistTest):
         meta.drop_all()
         metadata.create_all()
         
-    @testing.unsupported('oracle')
-    def test_mapping(self):
-        # TODO: this test should be moved to the ORM tests, tests should be
-        # added to this module testing SQL syntax and joins, etc.
-        class A(object):pass
-        class B(object):pass
-        
-        mapper(A, t1, properties={
-            't2s':relation(B),
-            'a':t1.c[u'méil'],
-            'b':t1.c[u'\u6e2c\u8a66']
-        })
-        mapper(B, t2)
-        sess = create_session()
-        a1 = A()
-        b1 = B()
-        a1.t2s.append(b1)
-        sess.save(a1)
-        sess.flush()
-        sess.clear()
-        new_a1 = sess.query(A).filter(t1.c[u'méil'] == a1.a).one()
-        assert new_a1.a == a1.a
-        assert new_a1.t2s[0].a == b1.a
-        sess.clear()
 
-        new_a1 = sess.query(A).options(eagerload('t2s')).filter(t1.c[u'méil'] == a1.a).one()
-        assert new_a1.a == a1.a
-        assert new_a1.t2s[0].a == b1.a
-        sess.clear()
 
-        new_a1 = sess.query(A).filter(A.a == a1.a).one()
-        assert new_a1.a == a1.a
-        assert new_a1.t2s[0].a == b1.a
-        sess.clear()
-        
 if __name__ == '__main__':
     testbase.main()