From 63c3ca28abab7f12592bc3e8bcd0b05749cd0053 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Tue, 30 Jul 2013 19:06:26 -0400 Subject: Starting to write unit tests... --- mediagoblin/tests/test_sql_migrations.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'mediagoblin/tests/test_sql_migrations.py') diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py index 2fc4c043..86bb989a 100644 --- a/mediagoblin/tests/test_sql_migrations.py +++ b/mediagoblin/tests/test_sql_migrations.py @@ -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 -- cgit v1.2.3 From 860fa806ee3af0260b9f8f6f02dd606fb55678f5 Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Tue, 30 Jul 2013 19:42:26 -0400 Subject: In this commit I added a few unittests to account for Foundations. There were only a few tests I had to add to mediagoblin/tests/test_sql_migrations.py beca- -use the foundation creation only happens at database initialization. --- mediagoblin/tests/test_sql_migrations.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'mediagoblin/tests/test_sql_migrations.py') diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py index 86bb989a..a004aa43 100644 --- a/mediagoblin/tests/test_sql_migrations.py +++ b/mediagoblin/tests/test_sql_migrations.py @@ -58,8 +58,8 @@ 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}]} +FOUNDATIONS = {Creature1:[{'name':u'goblin','num_legs':2,'is_demon':False}, + {'name':u'cerberus','num_legs':4,'is_demon':True}]} SET1_MIGRATIONS = {} @@ -574,7 +574,7 @@ def test_set1_to_set3(): printer = CollectingPrinter() migration_manager = MigrationManager( - u'__main__', SET1_MODELS, SET1_FOUNDATIONS, SET1_MIGRATIONS, Session(), + u'__main__', SET1_MODELS, FOUNDATIONS, SET1_MIGRATIONS, Session(), printer) # Check latest migration and database current migration @@ -593,6 +593,7 @@ def test_set1_to_set3(): assert migration_manager.latest_migration == 0 assert migration_manager.database_current_migration == 0 + # Install the initial set # ----------------------- @@ -600,7 +601,7 @@ def test_set1_to_set3(): # Try to "re-migrate" with same manager settings... nothing should happen migration_manager = MigrationManager( - u'__main__', SET1_MODELS, SET1_FOUNDATIONS, SET1_MIGRATIONS, + u'__main__', SET1_MODELS, FOUNDATIONS, SET1_MIGRATIONS, Session(), printer) assert migration_manager.init_or_migrate() == None @@ -642,6 +643,20 @@ def test_set1_to_set3(): # Now check to see if stuff seems to be in there. session = Session() + # Check the creation of the foundation rows on the creature table + creature = session.query(Creature1).filter_by( + name=u'goblin').one() + assert creature.num_legs == 2 + assert creature.is_demon == False + + creature = session.query(Creature1).filter_by( + name=u'cerberus').one() + assert creature.num_legs == 4 + assert creature.is_demon == True + + + # Check the creation of the inserted rows on the creature and levels tables + creature = session.query(Creature1).filter_by( name=u'centipede').one() assert creature.num_legs == 100 @@ -682,7 +697,7 @@ def test_set1_to_set3(): # isn't said to be updated yet printer = CollectingPrinter() migration_manager = MigrationManager( - u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(), + u'__main__', SET3_MODELS, FOUNDATIONS, SET3_MIGRATIONS, Session(), printer) assert migration_manager.latest_migration == 8 @@ -709,7 +724,7 @@ def test_set1_to_set3(): # Make sure version matches expected migration_manager = MigrationManager( - u'__main__', SET3_MODELS, SET3_MIGRATIONS, Session(), + u'__main__', SET3_MODELS, FOUNDATIONS, SET3_MIGRATIONS, Session(), printer) assert migration_manager.latest_migration == 8 assert migration_manager.database_current_migration == 8 -- cgit v1.2.3 From 84c1cd7c52e7a07f2e0605433f255d946fe2737a Mon Sep 17 00:00:00 2001 From: tilly-Q Date: Wed, 31 Jul 2013 20:50:38 -0400 Subject: I added a few more unitests in this commit. It now confirms that even after mi- -gration, there is only one of each Foundation object. --- mediagoblin/tests/test_sql_migrations.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'mediagoblin/tests/test_sql_migrations.py') diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py index a004aa43..3d67fdf6 100644 --- a/mediagoblin/tests/test_sql_migrations.py +++ b/mediagoblin/tests/test_sql_migrations.py @@ -59,7 +59,8 @@ class Level1(Base1): SET1_MODELS = [Creature1, Level1] FOUNDATIONS = {Creature1:[{'name':u'goblin','num_legs':2,'is_demon':False}, - {'name':u'cerberus','num_legs':4,'is_demon':True}]} + {'name':u'cerberus','num_legs':4,'is_demon':True}] + } SET1_MIGRATIONS = {} @@ -790,6 +791,15 @@ def test_set1_to_set3(): # Now check to see if stuff seems to be in there. session = Session() + + + # Start with making sure that the foundations did not run again + assert session.query(Creature3).filter_by( + name=u'goblin').count() == 1 + assert session.query(Creature3).filter_by( + name=u'cerberus').count() == 1 + + # Then make sure the models have been migrated correctly creature = session.query(Creature3).filter_by( name=u'centipede').one() assert creature.num_limbs == 100.0 -- cgit v1.2.3