Files
computer-playbook/tests/integration/infrastructure/backups/test_enabled.py
T
kevinveenbirkenbachandClaude Opus 4.7 4ac7a95ec6 refactor(tests): split overflowing folders into thematic subdirs
Reorganises four folders that exceeded the 12-item readability limit:

- tests/lint/repository/ (27 -> 11): structure/, naming/, documentation/,
  python/, dependencies/, shell/, yaml/, network/, settings/
- tests/integration/ (25 -> 7): ansible/, infrastructure/, iam/, meta/
  (24 sibling dirs grouped under 4 super-categories)
- tests/integration/roles/ (13 -> 10): naming/, playwright/, dashboard/
- tests/unit/utils/ (15 -> 12): certs/ for 3 cert/TLS test files

Renames 7 test files whose name duplicated the new folder name
(e.g. test_no_direct_yaml_calls.py -> yaml/test_no_direct_calls.py,
test_dashboard_integration_scope.py -> dashboard/test_integration_scope.py).

Adjusts parents[N] in moved __init__.py files, fixes __file__-based
path resolution in 8 tests, updates self-path whitelists, and uses
absolute imports for PROJECT_ROOT re-exports (ruff TID252).

Adds README.md to each new subfolder following the existing scope
template. Updates all docs links (suppression.md, base.md, email.md,
playwright spec/parity docs, 005-/019- requirements) to new paths.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 14:23:32 +02:00

62 lines
2.2 KiB
Python

import os
import unittest
from pathlib import Path
import yaml
from utils.cache.yaml import load_yaml_any
from utils.roles.mapping import ROLE_FILE_META_SERVICES
class TestBackupsEnabledIntegrity(unittest.TestCase):
def setUp(self):
# Path to the roles directory
self.roles_dir = str(
Path(str(Path(str(Path(__file__).parent)) / "../../../../roles")).resolve()
)
def test_backups_enabled_image_consistency(self):
"""
Ensure that if `backups.enabled` is set for any services[*]:
- it's a boolean value
- the containing service dict has an `image` entry at the same level
"""
for role in os.listdir(self.roles_dir):
docker_config_path = str(
Path(self.roles_dir) / role / ROLE_FILE_META_SERVICES
)
if not Path(docker_config_path).is_file():
continue
try:
config = load_yaml_any(docker_config_path) or {}
except yaml.YAMLError as e:
self.fail(f"YAML parsing failed for {docker_config_path}: {e}")
continue
# Per the file root of meta/services.yml IS the
# services map (no `compose.services` wrapper).
services = config if isinstance(config, dict) else {}
for service_key, service in services.items():
if not isinstance(service, dict):
continue
backups_cfg = service.get("backups", {}) or {}
if "enabled" in backups_cfg:
with self.subTest(role=role, service=service_key):
self.assertIsInstance(
backups_cfg["enabled"],
bool,
f"`backups.enabled` in role '{role}', service '{service_key}' must be a boolean.",
)
self.assertIn(
"image",
service,
f"`image` is required in role '{role}', service '{service_key}' when `backups.enabled` is defined.",
)
if __name__ == "__main__":
unittest.main()