diff options
| -rw-r--r-- | lib/sqlalchemy/orm/mapper.py | 2 | ||||
| -rw-r--r-- | test/orm/fixtures.py | 11 | ||||
| -rw-r--r-- | test/orm/unitofwork.py | 67 | ||||
| -rw-r--r-- | test/sql/unicode.py | 34 |
4 files changed, 77 insertions, 37 deletions
diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index 3870852d2..86e5d3387 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -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 diff --git a/test/orm/fixtures.py b/test/orm/fixtures.py index d3d95a6b5..33e0a419b 100644 --- a/test/orm/fixtures.py +++ b/test/orm/fixtures.py @@ -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: diff --git a/test/orm/unitofwork.py b/test/orm/unitofwork.py index 0a7df2a36..41400a333 100644 --- a/test/orm/unitofwork.py +++ b/test/orm/unitofwork.py @@ -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 diff --git a/test/sql/unicode.py b/test/sql/unicode.py index 19e78ed59..8174ab8b6 100644 --- a/test/sql/unicode.py +++ b/test/sql/unicode.py @@ -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() |
