feat: add model groups, verified registration and CNY credit grants
This commit is contained in:
1 parent
f5ba6cb255
commit
7a18db2123
40 files changed
+1980
-263
No files matched your search
@@ -0,0 +1,66 @@
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import tempfile
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from test_deploy import configuration, DIRECTORY
|
||||
|
||||
sys.path.insert(0, str(DIRECTORY))
|
||||
SPEC = importlib.util.spec_from_file_location("backup_database", DIRECTORY / "backup_database.py")
|
||||
backup_database = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(backup_database)
|
||||
|
||||
|
||||
class BackupTests(unittest.TestCase):
|
||||
def test_wrong_database_is_rejected_before_export(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
config = configuration()
|
||||
config["services"]["moyi-api"]["environment"]["SPRING_DATASOURCE_URL"] = "jdbc:postgresql://rds.internal:5432/another_app"
|
||||
deploy = SimpleNamespace(HERE=Path(root), preflight=lambda *args: config)
|
||||
with patch.object(backup_database.shutil, "which", side_effect=lambda name: name), \
|
||||
patch.object(backup_database, "check_container"), \
|
||||
patch.object(backup_database, "run") as command:
|
||||
with self.assertRaisesRegex(backup_database.MaintenanceError, "target"):
|
||||
backup_database.backup(deploy, "tunnel", Path(root) / "backups")
|
||||
command.assert_not_called()
|
||||
|
||||
def test_complete_marker_requires_successful_archive_validation(self):
|
||||
for corrupt in (False, True):
|
||||
with self.subTest(corrupt=corrupt), tempfile.TemporaryDirectory() as root:
|
||||
directory = Path(root)
|
||||
(directory / ".env.cloud").write_text("MOYI_SMTP_PASSWORD='test-only-secret'\n")
|
||||
deploy = SimpleNamespace(HERE=directory, preflight=lambda *args: configuration())
|
||||
seen = []
|
||||
|
||||
def command(argv, **kwargs):
|
||||
seen.append(argv)
|
||||
self.assertNotIn("test-only-rds-password", " ".join(argv))
|
||||
if argv[0] == "psql":
|
||||
return "moyi_control"
|
||||
if argv[0] == "pg_dump":
|
||||
Path(next(item[7:] for item in argv if item.startswith("--file="))).write_bytes(b"test archive")
|
||||
if argv[0] == "pg_restore" and corrupt:
|
||||
raise backup_database.MaintenanceError("Invalid archive")
|
||||
return ""
|
||||
|
||||
with patch.object(backup_database.shutil, "which", side_effect=lambda name: name), \
|
||||
patch.object(backup_database, "check_container"), patch.object(backup_database, "run", side_effect=command):
|
||||
if corrupt:
|
||||
with self.assertRaisesRegex(backup_database.MaintenanceError, "Invalid archive"):
|
||||
backup_database.backup(deploy, "tunnel", directory / "backups")
|
||||
self.assertEqual([], list((directory / "backups").rglob("backup-complete.json")))
|
||||
else:
|
||||
destination = backup_database.backup(deploy, "tunnel", directory / "backups")
|
||||
report = json.loads((destination / "backup-complete.json").read_text())
|
||||
self.assertEqual(report["database"], "moyi_control")
|
||||
self.assertEqual((destination / "env.cloud").read_bytes(), (directory / ".env.cloud").read_bytes())
|
||||
self.assertEqual(set(report["sha256"]), {"env.cloud", "moyi_control.dump"})
|
||||
self.assertEqual([argv[0] for argv in seen], ["psql", "pg_dump", "pg_restore"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user