"""Real-Postgres proof that every instance has one id lineage, that a full backup carries it, and that adopting a backup's id replaces this one's.""" import io import pytest from grimoire.models import async_session from grimoire.services import backup from grimoire.services.backup_file import read_archive, write_archive_to from grimoire.services.instance import adopt_instance_id, get_instance_id pytestmark = [pytest.mark.integration, pytest.mark.usefixtures("_dispose_engine")] async def test_the_migration_gave_this_instance_an_id_and_it_stays_put(): first = await get_instance_id() assert first and len(first) >= 32 assert await get_instance_id() == first async def test_a_full_backup_carries_the_instance_id_through_the_tar(): payload = await backup.export_full_backup() assert payload["instance_id"] == await get_instance_id() out = io.BytesIO() write_archive_to(payload, out, app_version="test") out.seek(0) assert read_archive(out)["instance_id"] == payload["instance_id"] async def test_adopting_a_backups_id_replaces_this_instances(): own = await get_instance_id() try: async with async_session() as s: await adopt_instance_id(s, "adopted-lineage") await s.commit() assert await get_instance_id() == "adopted-lineage" finally: async with async_session() as s: await adopt_instance_id(s, own) await s.commit() assert await get_instance_id() == own