]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
merge tip
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Nov 2010 00:01:17 +0000 (19:01 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 19 Nov 2010 00:01:17 +0000 (19:01 -0500)
1  2 
lib/sqlalchemy/orm/__init__.py
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/properties.py
test/ext/test_declarative.py
test/orm/test_mapper.py
test/orm/test_relationships.py

Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 566af48e8463289db10af66ffce1bd761e0028e8,03efa01832f1b6cb0d20dcafcc6709de5c9cb813..ff4ea59d623ed0c93d354f5c5265f1f0b2865662
@@@ -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):
      
          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
              
              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 <symbol 'ONETOMANY>.  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 <symbol 'ONETOMANY>.  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 <symbol 'MANYTOONE>.  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 <symbol 'MANYTOONE>.  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):
  
          # can't be sure of ordering here
          assert_raises_message(sa.exc.ArgumentError, 
-                     "both of the same direction <symbol 'ONETOMANY>.  Did you "
-                     "mean to set remote_side on the many-to-one side ?", sa.orm.configure_mappers)
+             "both of the same direction <symbol 'ONETOMANY>.  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):
  
          # can't be sure of ordering here
          assert_raises_message(sa.exc.ArgumentError, 
-                     "both of the same direction <symbol 'MANYTOONE>.  Did you "
-                     "mean to set remote_side on the many-to-one side ?", sa.orm.configure_mappers)
+             "both of the same direction <symbol 'MANYTOONE>.  Did you "
+             "mean to set remote_side on the many-to-one side ?", 
 -            sa.orm.compile_mappers)
++            configure_mappers)
  
          
  class InvalidRelationshipEscalationTest(_base.MappedTest):
  
          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):
  
          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):
  
          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):
  
          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
  
          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):
  
          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)]
  
          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={
          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={
          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