Starting to write unit tests...
authortilly-Q <nattilypigeonfowl@gmail.com>
Tue, 30 Jul 2013 23:06:26 +0000 (19:06 -0400)
committertilly-Q <nattilypigeonfowl@gmail.com>
Tue, 30 Jul 2013 23:06:26 +0000 (19:06 -0400)
mediagoblin/db/migration_tools.py
mediagoblin/tests/test_sql_migrations.py

index ad13768374db97f1c810bcaaed283e233e59a4dc..e75f37572c6cb036ed7f8787d313f1e8ecc9fac6 100644 (file)
@@ -147,10 +147,11 @@ class MigrationManager(object):
             in mediagoblin.db.models
         """
         for Model, rows in self.foundations.items():
-            print u'\n  + Laying foundations for %s table' % (Model.__name__)
+            self.printer(u'   + Laying foundations for %s table\n' % 
+                (Model.__name__))
             for parameters in rows:
                 new_row = Model(**parameters)
-                new_row.save()
+                self.session.add(new_row)
 
     def create_new_migration_record(self):
         """
@@ -215,9 +216,8 @@ class MigrationManager(object):
             self.init_tables()
             # auto-set at latest migration number
             self.create_new_migration_record()
-            self.populate_table_foundations()
-            
             self.printer(u"done.\n")
+            self.populate_table_foundations()
             self.set_current_migration()
             return u'inited'
 
index 2fc4c0436c1c5db60f2b5674b126d2214d89aaea..86bb989a8005ff42119301788e4d8dbc976c267f 100644 (file)
@@ -58,6 +58,9 @@ class Level1(Base1):
 
 SET1_MODELS = [Creature1, Level1]
 
+SET1_FOUNDATIONS = {Creature1:[{'name':u'goblin','num_legs':2,'is_demon':False},
+                               {'name':u'cerberus','num_legs':4,'is_demon':True}]}
+
 SET1_MIGRATIONS = {}
 
 #######################################################
@@ -542,7 +545,6 @@ def _insert_migration3_objects(session):
 
     session.commit()
 
-
 def create_test_engine():
     from sqlalchemy import create_engine
     engine = create_engine('sqlite:///:memory:', echo=False)
@@ -572,7 +574,7 @@ def test_set1_to_set3():
 
     printer = CollectingPrinter()
     migration_manager = MigrationManager(
-        u'__main__', SET1_MODELS, SET1_MIGRATIONS, Session(),
+        u'__main__', SET1_MODELS, SET1_FOUNDATIONS, SET1_MIGRATIONS, Session(),
         printer)
 
     # Check latest migration and database current migration
@@ -585,7 +587,8 @@ def test_set1_to_set3():
     assert result == u'inited'
     # Check output
     assert printer.combined_string == (
-        "-> Initializing main mediagoblin tables... done.\n")
+        "-> Initializing main mediagoblin tables... done.\n" + \
+        "   + Laying foundations for Creature1 table\n"    )
     # Check version in database
     assert migration_manager.latest_migration == 0
     assert migration_manager.database_current_migration == 0
@@ -597,8 +600,8 @@ def test_set1_to_set3():
 
     # Try to "re-migrate" with same manager settings... nothing should happen
     migration_manager = MigrationManager(
-        u'__main__', SET1_MODELS, SET1_MIGRATIONS, Session(),
-        printer)
+        u'__main__', SET1_MODELS, SET1_FOUNDATIONS, SET1_MIGRATIONS, 
+        Session(), printer)
     assert migration_manager.init_or_migrate() == None
 
     # Check version in database