Merge branch 'main' into feature/store-i18n

This commit is contained in:
kevinveenbirkenbach committed 2026-10-17 20:51:29 +02:00
commit f79ddac220
9 files changed
+73 -6

No files matched your search

+55
View File
@@ -16,6 +16,7 @@ import tempfile
import textwrap
import unittest
from pathlib import Path
from unittest import mock
from utils.cache import _reset_cache_for_tests
from utils.cache import applications as cache_apps
@@ -422,6 +423,60 @@ class TestGetMergedApplicationsCarrierFact(unittest.TestCase):
)
class TestNestedLookupsReuseTheUnrenderedView(unittest.TestCase):
def setUp(self) -> None:
_reset_cache_for_tests()
def test_nested_calls_during_one_render_build_the_defaults_once(self):
with tempfile.TemporaryDirectory() as tmp:
roles = _seed_minimal_roles(Path(tmp))
_write(
roles / "web-app-foo" / ROLE_FILE_META_SERVICES,
"""
foo:
image: "pre-{{ nested }}"
version: "v-{{ nested }}"
""",
)
variables = {
"applications": {
"web-app-foo": {"volumes": {"data": {"type": "volume"}}}
}
}
nested_views = []
class _NestingTemplar:
def __init__(self) -> None:
self.available_variables: dict = {}
def template(self, value, **_kwargs):
nested_views.append(
cache_apps.get_merged_applications(
variables=self.available_variables,
roles_dir=roles,
templar=self,
)
)
return "rendered"
with mock.patch.object(
cache_apps,
"get_application_defaults",
wraps=cache_apps.get_application_defaults,
) as defaults:
rendered = cache_apps.get_merged_applications(
variables=variables, roles_dir=roles, templar=_NestingTemplar()
)
self.assertEqual(defaults.call_count, 1)
self.assertGreaterEqual(len(nested_views), 2)
self.assertTrue(all(view is nested_views[0] for view in nested_views))
self.assertIn("volumes", nested_views[0]["web-app-foo"])
self.assertEqual(
rendered["web-app-foo"]["services"]["foo"]["image"], "rendered"
)
class TestRecursiveMetaWalk(unittest.TestCase):
"""`_build_role_base_config` walks the whole `meta/` tree: every
`meta/**/*.yml` lands at the matching nested path under