From: Mike Bayer Date: Fri, 19 Nov 2010 00:01:17 +0000 (-0500) Subject: merge tip X-Git-Tag: rel_0_7b1~239^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6dfbe839aaf026e72ecb079fc7608ad6c09babf8;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git merge tip --- 6dfbe839aaf026e72ecb079fc7608ad6c09babf8 diff --cc test/orm/test_relationships.py index 566af48e84,03efa01832..ff4ea59d62 --- a/test/orm/test_relationships.py +++ b/test/orm/test_relationships.py @@@ -5,7 -5,9 +5,9 @@@ from sqlalchemy.test import testin from sqlalchemy import Integer, String, ForeignKey, MetaData, and_ from sqlalchemy.test.schema import Table, Column from sqlalchemy.orm import mapper, relationship, relation, \ - backref, create_session, configure_mappers, clear_mappers, sessionmaker - backref, create_session, compile_mappers, \ ++ backref, create_session, configure_mappers, \ + clear_mappers, sessionmaker, attributes,\ + Session, composite, column_property from sqlalchemy.test.testing import eq_, startswith_ from test.orm import _base, _fixtures @@@ -918,9 -941,11 +941,11 @@@ class ManualBackrefTest(_fixtures.Fixtu }) assert_raises_message(sa.exc.ArgumentError, - r"reverse_property 'dingaling' on relationship User.addresses references " - "relationship Address.dingaling, which does not reference mapper Mapper\|User\|users", + r"reverse_property 'dingaling' on relationship " + "User.addresses references " + "relationship Address.dingaling, which does not " + "reference mapper Mapper\|User\|users", - compile_mappers) + configure_mappers) class JoinConditionErrorTest(testing.TestBase): @@@ -966,9 -991,10 +991,10 @@@ class C2(object): pass - mapper(C1, t1, properties={'c2':relationship(C2, primaryjoin=t1.join(t2))}) + mapper(C1, t1, properties={'c2':relationship(C2, + primaryjoin=t1.join(t2))}) mapper(C2, t2) - assert_raises(sa.exc.ArgumentError, compile_mappers) + assert_raises(sa.exc.ArgumentError, configure_mappers) def test_invalid_string_args(self): from sqlalchemy.ext.declarative import declarative_base @@@ -996,8 -1022,10 +1022,10 @@@ assert_raises_message( sa.exc.ArgumentError, - "Column-based expression object expected for argument '%s'; got: '%s', type %r" % (argname, arg[0], type(arg[0])), + "Column-based expression object expected " + "for argument '%s'; got: '%s', type %r" % + (argname, arg[0], type(arg[0])), - compile_mappers) + configure_mappers) def test_fk_error_raised(self): @@@ -1777,19 -1830,25 +1830,25 @@@ class InvalidRemoteSideTest(_base.Mappe 't1s':relationship(T1, backref='parent') }) - assert_raises_message(sa.exc.ArgumentError, "T1.t1s and back-reference T1.parent are " - "both of the same direction . Did you " - "mean to set remote_side on the many-to-one side ?", sa.orm.configure_mappers) + assert_raises_message(sa.exc.ArgumentError, + "T1.t1s and back-reference T1.parent are " + "both of the same direction . Did you " + "mean to set remote_side on the many-to-one side ?", - sa.orm.compile_mappers) ++ configure_mappers) @testing.resolve_artifact_names def test_m2o_backref(self): mapper(T1, t1, properties={ - 't1s':relationship(T1, backref=backref('parent', remote_side=t1.c.id), remote_side=t1.c.id) + 't1s':relationship(T1, + backref=backref('parent', remote_side=t1.c.id), + remote_side=t1.c.id) }) - assert_raises_message(sa.exc.ArgumentError, "T1.t1s and back-reference T1.parent are " - "both of the same direction . Did you " - "mean to set remote_side on the many-to-one side ?", sa.orm.configure_mappers) + assert_raises_message(sa.exc.ArgumentError, + "T1.t1s and back-reference T1.parent are " + "both of the same direction . Did you " + "mean to set remote_side on the many-to-one side ?", - sa.orm.compile_mappers) ++ configure_mappers) @testing.resolve_artifact_names def test_o2m_explicit(self): @@@ -1800,8 -1859,9 +1859,9 @@@ # can't be sure of ordering here assert_raises_message(sa.exc.ArgumentError, - "both of the same direction . Did you " - "mean to set remote_side on the many-to-one side ?", sa.orm.configure_mappers) + "both of the same direction . Did you " + "mean to set remote_side on the many-to-one side ?", - sa.orm.compile_mappers) ++ configure_mappers) @testing.resolve_artifact_names def test_m2o_explicit(self): @@@ -1812,8 -1874,9 +1874,9 @@@ # can't be sure of ordering here assert_raises_message(sa.exc.ArgumentError, - "both of the same direction . Did you " - "mean to set remote_side on the many-to-one side ?", sa.orm.configure_mappers) + "both of the same direction . Did you " + "mean to set remote_side on the many-to-one side ?", - sa.orm.compile_mappers) ++ configure_mappers) class InvalidRelationshipEscalationTest(_base.MappedTest): @@@ -1872,8 -1935,9 +1935,9 @@@ assert_raises_message( sa.exc.ArgumentError, - "Could not determine relationship direction for primaryjoin condition", - sa.orm.configure_mappers) + "Could not determine relationship direction " + "for primaryjoin condition", - sa.orm.compile_mappers) ++ configure_mappers) @testing.resolve_artifact_names def test_no_equated_fks(self): @@@ -1953,8 -2017,9 +2017,9 @@@ assert_raises_message( sa.exc.ArgumentError, - "Could not determine relationship direction for primaryjoin condition", - sa.orm.configure_mappers) + "Could not determine relationship direction for primaryjoin " + "condition", - sa.orm.compile_mappers) ++ configure_mappers) @testing.resolve_artifact_names def test_no_equated_self_ref(self): @@@ -2036,15 -2101,16 +2101,16 @@@ assert_raises_message( sa.exc.ArgumentError, - "Could not determine relationship direction for primaryjoin condition", - sa.orm.configure_mappers) + "Could not determine relationship direction for primaryjoin " + "condition", - sa.orm.compile_mappers) ++ configure_mappers) sa.orm.clear_mappers() mapper(Foo, foos_with_fks, properties={ 'bars':relationship(Bar, - primaryjoin=foos_with_fks.c.id==bars_with_fks.c.fid)}) + primaryjoin=foos_with_fks.c.id==bars_with_fks.c.fid)}) mapper(Bar, bars_with_fks) - sa.orm.compile_mappers() + sa.orm.configure_mappers() @testing.resolve_artifact_names def test_equated_self_ref(self): @@@ -2054,8 -2120,9 +2120,9 @@@ assert_raises_message( sa.exc.ArgumentError, - "Could not determine relationship direction for primaryjoin condition", - sa.orm.configure_mappers) + "Could not determine relationship direction for primaryjoin " + "condition", - sa.orm.compile_mappers) ++ configure_mappers) @testing.resolve_artifact_names @@@ -2067,8 -2134,9 +2134,9 @@@ assert_raises_message( sa.exc.ArgumentError, - "Could not determine relationship direction for primaryjoin condition", - sa.orm.configure_mappers) + "Could not determine relationship direction for primaryjoin " + "condition", - sa.orm.compile_mappers) ++ configure_mappers) class InvalidRelationshipEscalationTestM2M(_base.MappedTest): @@@ -2188,11 -2259,14 +2259,14 @@@ sa.orm.clear_mappers() mapper(Foo, foos, properties={ - 'bars': relationship(Bar, secondary=foobars_with_many_columns, - primaryjoin=foos.c.id==foobars_with_many_columns.c.fid, - secondaryjoin=foobars_with_many_columns.c.bid==bars.c.id)}) + 'bars': relationship(Bar, + secondary=foobars_with_many_columns, + primaryjoin=foos.c.id== + foobars_with_many_columns.c.fid, + secondaryjoin=foobars_with_many_columns.c.bid== + bars.c.id)}) mapper(Bar, bars) - sa.orm.compile_mappers() + sa.orm.configure_mappers() eq_( Foo.bars.property.synchronize_pairs, [(foos.c.id, foobars_with_many_columns.c.fid)] @@@ -2214,8 -2288,9 +2288,9 @@@ assert_raises_message( sa.exc.ArgumentError, - "Could not determine relationship direction for primaryjoin condition", - sa.orm.configure_mappers) + "Could not determine relationship direction for " + "primaryjoin condition", - sa.orm.compile_mappers) ++ configure_mappers) sa.orm.clear_mappers() mapper(Foo, foos, properties={ @@@ -2226,8 -2301,9 +2301,9 @@@ mapper(Bar, bars) assert_raises_message( sa.exc.ArgumentError, - "Could not locate any equated, locally mapped column pairs for primaryjoin condition ", - sa.orm.configure_mappers) + "Could not locate any equated, locally mapped column pairs for " + "primaryjoin condition ", - sa.orm.compile_mappers) ++ configure_mappers) sa.orm.clear_mappers() mapper(Foo, foos, properties={ @@@ -2277,10 -2353,73 +2353,73 @@@ assert_raises_message( sa.exc.ArgumentError, "Could not locate any equated, locally mapped column pairs for " - "secondaryjoin condition", sa.orm.compile_mappers) + "secondaryjoin condition", sa.orm.configure_mappers) + class ActiveHistoryFlagTest(_fixtures.FixtureTest): + run_inserts = None + run_deletes = None + + def _test_attribute(self, obj, attrname, newvalue): + sess = Session() + sess.add(obj) + oldvalue = getattr(obj, attrname) + sess.commit() + + # expired + assert attrname not in obj.__dict__ + + setattr(obj, attrname, newvalue) + eq_( + attributes.get_history(obj, attrname), + ([newvalue,], (), [oldvalue,]) + ) + + @testing.resolve_artifact_names + def test_column_property_flag(self): + mapper(User, users, properties={ + 'name':column_property(users.c.name, active_history=True) + }) + u1 = User(name='jack') + self._test_attribute(u1, 'name', 'ed') + + @testing.resolve_artifact_names + def test_relationship_property_flag(self): + mapper(Address, addresses, properties={ + 'user':relationship(User, active_history=True) + }) + mapper(User, users) + u1 = User(name='jack') + u2 = User(name='ed') + a1 = Address(email_address='a1', user=u1) + self._test_attribute(a1, 'user', u2) + + @testing.resolve_artifact_names + def test_composite_property_flag(self): + # active_history is implicit for composites + # right now, no flag needed + class MyComposite(object): + def __init__(self, description, isopen): + self.description = description + self.isopen = isopen + def __composite_values__(self): + return [self.description, self.isopen] + def __eq__(self, other): + return isinstance(other, MyComposite) and \ + other.description == self.description + mapper(Order, orders, properties={ + 'composite':composite( + MyComposite, + orders.c.description, + orders.c.isopen) + }) + o1 = Order(composite=MyComposite('foo', 1)) + self._test_attribute(o1, "composite", MyComposite('bar', 1)) + + class RelationDeprecationTest(_base.MappedTest): + """test usage of the old 'relation' function.""" + run_inserts = 'once' run_deletes = None