Starting to write unit tests...
This commit is contained in:
parent
08cd10d84f
commit
63c3ca28ab
@ -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'
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user