diff options
author | tilly-Q <nattilypigeonfowl@gmail.com> | 2013-08-20 12:02:20 -0400 |
---|---|---|
committer | tilly-Q <nattilypigeonfowl@gmail.com> | 2013-08-20 12:02:20 -0400 |
commit | e1561d048815e29b3b7c7e1c860d9cf0c4326f0a (patch) | |
tree | 691fe54e5b6a1dcb6799d673a99f01e850a6a9f9 /mediagoblin/tests/test_sql_migrations.py | |
parent | 8394febbe1408030d1afa8f3961d92341eefa474 (diff) | |
download | mediagoblin-e1561d048815e29b3b7c7e1c860d9cf0c4326f0a.tar.lz mediagoblin-e1561d048815e29b3b7c7e1c860d9cf0c4326f0a.tar.xz mediagoblin-e1561d048815e29b3b7c7e1c860d9cf0c4326f0a.zip |
This was a very small update, I'm hoping to rebase after this to solve some
other problems. I started looking at the tests in this update. This update I
spent fixing the tests to work with my new code.
--\ mediagoblin/db/migration_tools.py
--| Merging from ticket 679
--\ mediagoblin/db/migrations.py
--| Added unique constraint to Privilege.privilege_name
--\ mediagoblin/db/models.py
--| Deleted vestigial Privilege.is_admin_or_moderator method
--\ mediagoblin/templates/mediagoblin/moderation/user.html
--| Add a `Ban User` / `UnBan User` for admin
--\ mediagoblin/test/test_api.py
--| Fixed test with my new changes
--\ mediagoblin/test/test_auth.py
--| Try to fix test, still having problems
--\ mediagoblin/test/test_modelmethods.py
--| Wrote my first test for the User.has_privilege method
--\ mediagoblin/test/test_modelmethods.py
--| Fixed test with my new changes
--\ mediagoblin/test/test_sqlmigrations.py
--| Merging from ticket 679
--\ mediagoblin/test/tools.py
--| Editted add_fixture_user to allow for privileges rather than active column
Diffstat (limited to 'mediagoblin/tests/test_sql_migrations.py')
-rw-r--r-- | mediagoblin/tests/test_sql_migrations.py | 42 |
1 files changed, 35 insertions, 7 deletions
diff --git a/mediagoblin/tests/test_sql_migrations.py b/mediagoblin/tests/test_sql_migrations.py index 2fc4c043..3d67fdf6 100644 --- a/mediagoblin/tests/test_sql_migrations.py +++ b/mediagoblin/tests/test_sql_migrations.py @@ -58,6 +58,10 @@ 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}] + } + SET1_MIGRATIONS = {} ####################################################### @@ -542,7 +546,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 +575,7 @@ def test_set1_to_set3(): printer = CollectingPrinter() migration_manager = MigrationManager( - u'__main__', SET1_MODELS, SET1_MIGRATIONS, Session(), + u'__main__', SET1_MODELS, FOUNDATIONS, SET1_MIGRATIONS, Session(), printer) # Check latest migration and database current migration @@ -585,11 +588,13 @@ 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 + # Install the initial set # ----------------------- @@ -597,8 +602,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, FOUNDATIONS, SET1_MIGRATIONS, + Session(), printer) assert migration_manager.init_or_migrate() == None # Check version in database @@ -639,6 +644,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 @@ -679,7 +698,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 @@ -706,7 +725,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 @@ -772,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 |