]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- unit test for r4048
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 10 Jan 2008 22:45:07 +0000 (22:45 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 10 Jan 2008 22:45:07 +0000 (22:45 +0000)
lib/sqlalchemy/orm/mapper.py
test/orm/unitofwork.py

index 1451f4336c72204e6f13c4e3ac57a695b4c40596..c15ea3b159276cc3f5b98eef98dbc4251e6a42d7 100644 (file)
@@ -1153,7 +1153,6 @@ class Mapper(object):
                 self._set_state_attr_by_column(state, c, params[c.key])
         
         if deferred_props:
-            # TODO: need a unit test for this functionality
             if self.eager_defaults:
                 _instance_key = self._identity_key_from_state(state)
                 state.dict['_instance_key'] = _instance_key
index 4f191523cce60dcf688b52422a4f1d186fd3bc09..c31293e72bfe81a7d5997dc4b55f80a5e19855a8 100644 (file)
@@ -682,20 +682,21 @@ class DefaultTest(ORMTest):
     def define_tables(self, metadata):
         db = testbase.db
         use_string_defaults = db.engine.__module__.endswith('postgres') or db.engine.__module__.endswith('oracle') or db.engine.__module__.endswith('sqlite')
-
+        global hohoval, althohoval
+        
         if use_string_defaults:
             hohotype = String(30)
-            self.hohoval = "im hoho"
-            self.althohoval = "im different hoho"
+            hohoval = "im hoho"
+            althohoval = "im different hoho"
         else:
             hohotype = Integer
-            self.hohoval = 9
-            self.althohoval = 15
+            hohoval = 9
+            althohoval = 15
 
         global default_table
         default_table = Table('default_test', metadata,
         Column('id', Integer, Sequence("dt_seq", optional=True), primary_key=True),
-        Column('hoho', hohotype, PassiveDefault(str(self.hohoval))),
+        Column('hoho', hohotype, PassiveDefault(str(hohoval))),
         Column('counter', Integer, default=func.length("1234567")),
         Column('foober', String(30), default="im foober", onupdate="im the update")
         )
@@ -705,19 +706,19 @@ class DefaultTest(ORMTest):
         class Hoho(object):pass
         mapper(Hoho, default_table)
 
-        h1 = Hoho(hoho=self.althohoval)
+        h1 = Hoho(hoho=althohoval)
         h2 = Hoho(counter=12)
-        h3 = Hoho(hoho=self.althohoval, counter=12)
+        h3 = Hoho(hoho=althohoval, counter=12)
         h4 = Hoho()
         h5 = Hoho(foober='im the new foober')
         Session.commit()
 
-        self.assert_(h1.hoho==self.althohoval)
-        self.assert_(h3.hoho==self.althohoval)
+        self.assert_(h1.hoho==althohoval)
+        self.assert_(h3.hoho==althohoval)
 
         def go():
             # test deferred load of attribues, one select per instance
-            self.assert_(h2.hoho==h4.hoho==h5.hoho==self.hohoval)
+            self.assert_(h2.hoho==h4.hoho==h5.hoho==hohoval)
         self.assert_sql_count(testbase.db, go, 3)
 
         def go():
@@ -736,14 +737,24 @@ class DefaultTest(ORMTest):
 
         (h1, h2, h3, h4, h5) = l
 
-        self.assert_(h1.hoho==self.althohoval)
-        self.assert_(h3.hoho==self.althohoval)
-        self.assert_(h2.hoho==h4.hoho==h5.hoho==self.hohoval)
+        self.assert_(h1.hoho==althohoval)
+        self.assert_(h3.hoho==althohoval)
+        self.assert_(h2.hoho==h4.hoho==h5.hoho==hohoval)
         self.assert_(h3.counter == h2.counter == 12)
         self.assert_(h1.counter ==  h4.counter==h5.counter==7)
         self.assert_(h2.foober == h3.foober == h4.foober == 'im foober')
         self.assert_(h5.foober=='im the new foober')
 
+    def test_eager_defaults(self):
+        class Hoho(object):pass
+        mapper(Hoho, default_table, eager_defaults=True)
+        h1 = Hoho()
+        Session.commit()
+        
+        def go():
+            self.assert_(h1.hoho==hohoval)
+        self.assert_sql_count(testbase.db, go, 0)
+        
     def test_insert_nopostfetch(self):
         # populates the PassiveDefaults explicitly so there is no "post-update"
         class Hoho(object):pass