aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2022-11-09 11:52:49 +0300
committerFrederick Muriuki Muriithi2022-11-09 11:57:49 +0300
commitb8d33374ba4686fcadeed9f6c60f937f2eb19a89 (patch)
treec4300bd0908bc378ad15614caadcc5e6555bcb00 /tests
parente66ca1919381261a0fcdb744d1fc12e8f51739d8 (diff)
downloadgenenetwork3-b8d33374ba4686fcadeed9f6c60f937f2eb19a89.tar.gz
Tests: Provide backend fixture to (apply|rollback)_single_migration
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/auth/conftest.py9
-rw-r--r--tests/unit/auth/test_create_table_migrations.py6
-rw-r--r--tests/unit/auth/test_migration_init_data_in_resource_categories_table.py6
3 files changed, 11 insertions, 10 deletions
diff --git a/tests/unit/auth/conftest.py b/tests/unit/auth/conftest.py
index faecd32..b7e00bd 100644
--- a/tests/unit/auth/conftest.py
+++ b/tests/unit/auth/conftest.py
@@ -5,6 +5,7 @@ from typing import Union
from contextlib import closing
import pytest
+from yoyo.backends import DatabaseBackend
from yoyo import get_backend, read_migrations
from yoyo.migrations import Migration, MigrationList
@@ -20,13 +21,13 @@ def auth_migrations_dir(test_app_config): # pylint: disable=redefined-outer-name
"""Get the test application's auth database file"""
return test_app_config["AUTH_MIGRATIONS"]
-def apply_single_migration(db_uri: Union[Path, str], migration: Migration):
+def apply_single_migration(backend: DatabaseBackend, migration: Migration):
"""Utility to apply a single migration"""
- apply_migrations(get_backend(f"sqlite:///{db_uri}"), MigrationList([migration]))
+ apply_migrations(backend, MigrationList([migration]))
-def rollback_single_migration(db_uri: Union[Path, str], migration: Migration):
+def rollback_single_migration(backend: DatabaseBackend, migration: Migration):
"""Utility to rollback a single migration"""
- rollback_migrations(get_backend(f"sqlite:///{db_uri}"), MigrationList([migration]))
+ rollback_migrations(backend, MigrationList([migration]))
@pytest.fixture(scope="session")
def backend(auth_testdb_path): # pylint: disable=redefined-outer-name
diff --git a/tests/unit/auth/test_create_table_migrations.py b/tests/unit/auth/test_create_table_migrations.py
index 2263032..97719eb 100644
--- a/tests/unit/auth/test_create_table_migrations.py
+++ b/tests/unit/auth/test_create_table_migrations.py
@@ -33,7 +33,7 @@ def test_create_table(
cursor.execute("SELECT name FROM sqlite_schema WHERE type='table'")
result = cursor.fetchall()
assert the_table not in [row[0] for row in cursor.fetchall()]
- apply_single_migration(auth_testdb_path, get_migration(migration_path))
+ apply_single_migration(backend, get_migration(migration_path))
cursor.execute("SELECT name FROM sqlite_schema WHERE type='table'")
assert the_table in [row[0] for row in cursor.fetchall()]
@@ -53,10 +53,10 @@ def test_rollback_create_table(
older_migrations = migrations_up_to(migration_path, auth_migrations_dir)
apply_migrations(backend, older_migrations)
with closing(sqlite3.connect(auth_testdb_path)) as conn, closing(conn.cursor()) as cursor:
- apply_single_migration(auth_testdb_path, get_migration(migration_path))
+ apply_single_migration(backend, get_migration(migration_path))
cursor.execute("SELECT name FROM sqlite_schema WHERE type='table'")
assert the_table in [row[0] for row in cursor.fetchall()]
- rollback_single_migration(auth_testdb_path, get_migration(migration_path))
+ rollback_single_migration(backend, get_migration(migration_path))
cursor.execute("SELECT name FROM sqlite_schema WHERE type='table'")
assert the_table not in [row[0] for row in cursor.fetchall()]
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 59ef385..8c82c53 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
@@ -20,7 +20,7 @@ def test_apply_init_data(auth_testdb_path, auth_migrations_dir, backend):
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)
+ apply_single_migration(backend, the_migration)
cursor.execute("SELECT * FROM resource_categories")
results = cursor.fetchall()
assert len(results) == 3, "Expected 3 rows of data."
@@ -41,11 +41,11 @@ def test_rollback_init_data(auth_testdb_path, auth_migrations_dir, backend):
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)
+ apply_single_migration(backend, 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)
+ rollback_single_migration(backend, the_migration)
cursor.execute("SELECT * FROM resource_categories")
assert len(cursor.fetchall()) == 0, "Expected empty table."