railiance-platform/tests/test_offsite_restore_boundaries.py

22 lines
971 B
Python
Raw Normal View History

import importlib.util
from pathlib import Path
import tempfile
import unittest
from unittest.mock import patch
import sys
sys.path.insert(0,str(Path(__file__).resolve().parents[1]/'scripts'))
import verify_nextcloud_offsite_restore as transfer
import restore_forgejo_offsite_locally as restore
class RestoreBoundary(unittest.TestCase):
def test_missing_backup_never_fetches_credentials(self):
with tempfile.TemporaryDirectory() as d, patch.object(transfer,'bao') as bao:
with self.assertRaises(transfer.LaneError): transfer.run(Path(d)/'absent.zip.age',Path(d)/'stage',{})
bao.assert_not_called()
def test_truncated_backup_never_starts_docker(self):
with tempfile.TemporaryDirectory() as d, patch.object(restore.subprocess,'run') as command:
p=Path(d)/'fetched.zip';p.write_bytes(b'PK\x03\x04truncated')
with self.assertRaises(Exception): restore.run(p,{})
command.assert_not_called()