Test the revision lock of the CLI stages

The `@db_revision` decorator no longer skips its check under `TESTING`.

The tests replace `current_db_revision()` with the revision they need.
This commit is contained in:
Alexander Hess 2026-12-02 13:41:50 +01:00
commit 2add322a25
Signed by: alexander
GPG key ID: B46EDB4DFC26805D

View file

@ -0,0 +1,38 @@
"""Test the `velofy.console.decorators` module."""
import click
from velofy.console import decorators
REQUIRED = "abcdef123456"
@click.command()
@decorators.db_revision(REQUIRED)
def stage() -> None:
"""A stage locked to the `REQUIRED` revision."""
click.echo("stage executed")
def test_stage_runs_at_the_required_revision(cli, monkeypatch):
"""The stage runs if the database is at the required revision."""
monkeypatch.setattr(decorators, "current_db_revision", lambda: REQUIRED)
result = cli.invoke(stage)
assert result.exit_code == 0
assert "stage executed" in result.output
def test_stage_refuses_at_another_revision(cli, monkeypatch):
"""The stage refuses to run once the database has moved on."""
current = "fedcba654321"
monkeypatch.setattr(decorators, "current_db_revision", lambda: current)
result = cli.invoke(stage)
assert result.exit_code == 1
assert "stage executed" not in result.output
assert current in result.output
assert REQUIRED in result.output