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
1 changed files with 28 additions and 1 deletions
|
|
@ -1,7 +1,11 @@
|
|||
"""Test the `velofy.console.decorators` module."""
|
||||
|
||||
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
|
||||
|
||||
|
||||
|
|
@ -36,3 +40,26 @@ def test_stage_refuses_at_another_revision(cli, monkeypatch):
|
|||
assert "stage executed" not in result.output
|
||||
assert current 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