From 7034bf5ffb1498230ffb8f4da2f91cf2ca882845 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Tue, 8 Nov 2022 16:55:31 +0300 Subject: Migrations: Improve `resource_categories` data tests. * tests/unit/auth/test_migration_init_data_in_resource_categories_table.py: Test that the data is initialised properly. Test that rollback works as expected. --- ...ation_init_data_in_resource_categories_table.py | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/unit/auth') diff --git a/tests/unit/auth/test_migration_init_data_in_resource_categories_table.py b/tests/unit/auth/test_migration_init_data_in_resource_categories_table.py index 4b5a039..59ef385 100644 --- a/tests/unit/auth/test_migration_init_data_in_resource_categories_table.py +++ b/tests/unit/auth/test_migration_init_data_in_resource_categories_table.py @@ -24,5 +24,29 @@ def test_apply_init_data(auth_testdb_path, auth_migrations_dir, backend): cursor.execute("SELECT * FROM resource_categories") results = cursor.fetchall() assert len(results) == 3, "Expected 3 rows of data." + assert sorted(results) == sorted(( + ('fad071a3-2fc8-40b8-992b-cdefe7dcac79', 'mrna', 'mRNA Dataset'), + ('548d684b-d4d1-46fb-a6d3-51a56b7da1b3', 'phenotype', + 'Phenotype (Publish) Dataset'), + ('48056f84-a2a6-41ac-8319-0e1e212cba2a', 'genotype', + 'Genotype Dataset'))) rollback_migrations(backend, older_migrations + [the_migration]) + +@pytest.mark.unit_test +def test_rollback_init_data(auth_testdb_path, auth_migrations_dir, backend): + older_migrations = migrations_up_to(migration_path, auth_migrations_dir) + the_migration = get_migration(migration_path) + apply_migrations(backend, older_migrations) + with closing(sqlite3.connect(auth_testdb_path)) as conn, closing(conn.cursor()) as cursor: + cursor.execute("SELECT * FROM resource_categories") + assert len(cursor.fetchall()) == 0, "Expected empty table." + apply_single_migration(auth_testdb_path, the_migration) + cursor.execute("SELECT * FROM resource_categories") + results = cursor.fetchall() + assert len(results) == 3, "Expected 3 rows of data." + rollback_single_migration(auth_testdb_path, the_migration) + cursor.execute("SELECT * FROM resource_categories") + assert len(cursor.fetchall()) == 0, "Expected empty table." + + rollback_migrations(backend, older_migrations) -- cgit v1.2.3