Test reading the database revision
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m50s
All checks were successful
CI / Checks (Python 3.13) (push) Successful in 2m50s
In the "sequentially" variant of the test database, `current_db_revision()` must return the head of the migrations; in the "all_at_once" variant, there is no version table.
This commit is contained in:
parent
2add322a25
commit
35d0c7b409
2 changed files with 28 additions and 1 deletions
|
|
@ -12,7 +12,7 @@ import velofy
|
||||||
from velofy.db import connection
|
from velofy.db import connection
|
||||||
|
|
||||||
|
|
||||||
def current_db_revision() -> str | None: # pragma: no cover
|
def current_db_revision() -> str | None:
|
||||||
"""The `alembic` revision the database is at."""
|
"""The `alembic` revision the database is at."""
|
||||||
with connection.get_engine().connect() as conn:
|
with connection.get_engine().connect() as conn:
|
||||||
context = migration.MigrationContext.configure(
|
context = migration.MigrationContext.configure(
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
"""Test the `velofy.console.decorators` module."""
|
"""Test the `velofy.console.decorators` module."""
|
||||||
|
|
||||||
import click
|
import click
|
||||||
|
import pytest
|
||||||
|
from alembic import config as alembic_config
|
||||||
|
from alembic import script as alembic_script
|
||||||
|
|
||||||
|
import velofy
|
||||||
from velofy.console import decorators
|
from velofy.console import decorators
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -36,3 +40,26 @@ def test_stage_refuses_at_another_revision(cli, monkeypatch):
|
||||||
assert "stage executed" not in result.output
|
assert "stage executed" not in result.output
|
||||||
assert current in result.output
|
assert current in result.output
|
||||||
assert REQUIRED in result.output
|
assert REQUIRED in result.output
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.db
|
||||||
|
@pytest.mark.usefixtures("db_connection")
|
||||||
|
def test_current_db_revision(monkeypatch, request):
|
||||||
|
"""`current_db_revision()` reads the revision of the test database."""
|
||||||
|
# The migrations name the test database's version table
|
||||||
|
# after the test schema, as configured in migrations/env.py
|
||||||
|
monkeypatch.setattr(
|
||||||
|
velofy.config,
|
||||||
|
"ALEMBIC_TABLE",
|
||||||
|
f"{velofy.config.ALEMBIC_TABLE}_{velofy.config.CLEAN_SCHEMA}",
|
||||||
|
)
|
||||||
|
|
||||||
|
result = decorators.current_db_revision()
|
||||||
|
|
||||||
|
if request.node.callspec.params["db_connection"] == "sequentially":
|
||||||
|
cfg = alembic_config.Config("alembic.ini")
|
||||||
|
head = alembic_script.ScriptDirectory.from_config(cfg).get_current_head()
|
||||||
|
assert result == head
|
||||||
|
|
||||||
|
else: # "all_at_once" creates no version table
|
||||||
|
assert result is None
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue