Files
Scrobbler/tests/test_migrations.py
T
mattandClaude Opus 5.5 c79c42ee00
CI / validate-monitoring (push) Successful in 7s
CI / lint (push) Successful in 12s
CI / test (push) Successful in 50s
CI / images (push) Skipped
CI / assets (push) Skipped
CI / python-package (push) Skipped
CI / notify (push) Successful in 5s
Federation module skeleton and its own migration branch (phase 0, steps 3-4)
- scrobbler.federation with init_app() as its only entry point, called
  from create_app(); does nothing unless FEDERATION_ENABLED
- FederationConfig validates FEDERATION_DOMAIN (bare host) and
  FEDERATION_BASE_URL (https) when enabled, with clear errors
- federation/protocol/ package for pure, framework-free protocol code
- Package README with the boundary rules, configuration and migration
  workflow; .env.example lists the settings (off)
- Alembic: existing history labelled `core`; new empty `federation`
  branch root (depends on the core users table). Everything upgrades
  `heads` (entrypoint, CI, tests); tests check both branches apply and
  that federation can be removed without touching core

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MK52BGoJbPhZ1vSFuKcGUW
2026-09-25 19:59:47 +01:00

43 lines
1.3 KiB
Python

import pytest
from alembic.script import ScriptDirectory
from flask_migrate import downgrade, upgrade
from sqlalchemy import text
from scrobbler.extensions import db
@pytest.fixture
def scripts(app):
return ScriptDirectory(app.extensions["migrate"].directory)
def applied() -> set[str]:
return set(db.session.execute(text("SELECT version_num FROM alembic_version")).scalars())
def head_of(scripts: ScriptDirectory, branch: str) -> str:
return scripts.get_revision(f"{branch}@head").revision
def test_there_are_exactly_two_branches(scripts):
labels = {label for rev in scripts.walk_revisions() for label in rev.branch_labels}
assert labels == {"core", "federation"}
assert len(scripts.get_heads()) == 2
def test_both_branches_are_applied(app, scripts):
assert applied() == {head_of(scripts, "core"), head_of(scripts, "federation")}
def test_federation_branch_can_be_removed_without_touching_core(app, scripts, user):
core, federation = head_of(scripts, "core"), head_of(scripts, "federation")
try:
db.session.commit()
downgrade(revision="federation@base")
assert applied() == {core}
assert db.session.execute(text("SELECT count(*) FROM users")).scalar_one() == 1
finally:
db.session.rollback()
upgrade(revision="heads")
assert applied() == {core, federation}