aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-11-08 16:55:31 +0300
committerFrederick Muriuki Muriithi2022-11-08 16:55:31 +0300
commit7034bf5ffb1498230ffb8f4da2f91cf2ca882845 (patch)
tree19328d98e6d4ded088bc0d70bb330b2ae1016ddc
parent3a44dd8750a212b5ed26cb0882dd1ad3dc3085d6 (diff)
downloadgenenetwork3-7034bf5ffb1498230ffb8f4da2f91cf2ca882845.tar.gz
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.
-rw-r--r--tests/unit/auth/test_migration_init_data_in_resource_categories_table.py24
1 files changed, 24 insertions, 0 deletions
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)