You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
57 lines
1.8 KiB
57 lines
1.8 KiB
import os |
|
import subprocess |
|
|
|
import pytest |
|
|
|
from core.backup import ( |
|
DatabaseSnapshot, |
|
DatabaseTarget, |
|
_read_snapshot, |
|
run_synthetic_restore_verification, |
|
) |
|
|
|
|
|
def test_backup_configuration_is_allow_gated(settings): |
|
assert settings.BACKUP_ROOT == "/app/backups" |
|
if not os.environ.get("BACKUP_SOURCE_HOST"): |
|
assert settings.BACKUP_VERIFY_ALLOWED is False |
|
|
|
|
|
def test_application_image_installs_matching_postgresql_client(): |
|
result = subprocess.run( |
|
["pg_dump", "--version"], check=True, capture_output=True, text=True |
|
) |
|
|
|
assert result.stdout.startswith("pg_dump (PostgreSQL) 17.") |
|
|
|
|
|
@pytest.mark.skipif( |
|
not all( |
|
os.environ.get(name) |
|
for name in ( |
|
"BACKUP_SOURCE_HOST", |
|
"BACKUP_SOURCE_NAME", |
|
"BACKUP_SOURCE_USER", |
|
"BACKUP_SOURCE_PASSWORD", |
|
) |
|
), |
|
reason="requires the backup profile's disposable databases", |
|
) |
|
def test_synthetic_restore_is_repeatable_and_leaves_both_databases_empty( |
|
settings, django_db_blocker |
|
): |
|
with django_db_blocker.unblock(): |
|
first = run_synthetic_restore_verification() |
|
second = run_synthetic_restore_verification() |
|
source = DatabaseTarget( |
|
host=os.environ["BACKUP_SOURCE_HOST"], |
|
port=os.environ.get("BACKUP_SOURCE_PORT", "5432"), |
|
name=os.environ["BACKUP_SOURCE_NAME"], |
|
user=os.environ["BACKUP_SOURCE_USER"], |
|
password=os.environ["BACKUP_SOURCE_PASSWORD"], |
|
) |
|
target = DatabaseTarget.from_default(settings.DATABASES["default"]) |
|
empty = DatabaseSnapshot(migrations=(), row_counts={}) |
|
assert first.row_counts == second.row_counts |
|
assert _read_snapshot(source) == empty |
|
assert _read_snapshot(target) == empty
|
|
|