mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-28 22:06:31 +00:00
Merge branch 'fix/codescan/cyclic-imports' into fix/codescan/python-hygiene
# Conflicts: # cli/administration/deploy/development/down.py # cli/administration/deploy/development/inventory/__init__.py # tests/unit/python/utils/cache/test_base.py # tests/unit/python/utils/cache/test_data.py
This commit is contained in:
commit
989cd45f56
158 files changed
+1067
-645
No files matched your search
+1
-1
@@ -18,12 +18,12 @@ import unittest
|
||||
import unittest.mock as mock
|
||||
from pathlib import Path
|
||||
|
||||
from utils.cache import _reset_cache_for_tests
|
||||
from utils.cache import applications as cache_apps
|
||||
from utils.cache.carrier import (
|
||||
APPLICATIONS_RENDERED_FACT,
|
||||
merged_applications_cache_key,
|
||||
)
|
||||
from utils.cache.reset import _reset_cache_for_tests
|
||||
from utils.cache.yaml import load_yaml_any
|
||||
from utils.roles.mapping import (
|
||||
ROLE_DIR_META_ADDONS,
|
||||
|
||||
+2
-1
@@ -17,7 +17,8 @@ import unittest
|
||||
import unittest.mock as mock
|
||||
from pathlib import Path
|
||||
|
||||
from utils.cache import PROJECT_ROOT, _reset_cache_for_tests, base
|
||||
from utils.cache import PROJECT_ROOT, base
|
||||
from utils.cache.reset import _reset_cache_for_tests
|
||||
from utils.domains.default_primary import default_domain_primary
|
||||
from utils.paths import FILE_TOKENS
|
||||
|
||||
|
||||
+2
-1
@@ -5,7 +5,7 @@ import textwrap
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
from utils.cache import PROJECT_ROOT, _reset_cache_for_tests
|
||||
from utils.cache import PROJECT_ROOT
|
||||
from utils.cache.applications import get_application_defaults
|
||||
from utils.cache.base import (
|
||||
ROLES_DIR,
|
||||
@@ -13,6 +13,7 @@ from utils.cache.base import (
|
||||
_fingerprint_mapping,
|
||||
_stable_variables_signature,
|
||||
)
|
||||
from utils.cache.reset import _reset_cache_for_tests
|
||||
from utils.cache.users import (
|
||||
_build_users,
|
||||
_compute_reserved_usernames,
|
||||
|
||||
+1
-1
@@ -16,9 +16,9 @@ import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from utils.cache import _reset_cache_for_tests
|
||||
from utils.cache import domains as cache_domains
|
||||
from utils.cache.base import _RENDER_GUARD
|
||||
from utils.cache.reset import _reset_cache_for_tests
|
||||
from utils.domains.default_primary import default_domain_primary
|
||||
from utils.roles.mapping import ROLE_FILE_META_SERVICES, ROLE_FILE_META_USERS
|
||||
|
||||
|
||||
+1
-1
@@ -15,7 +15,6 @@ from . import PROJECT_ROOT
|
||||
if str(PROJECT_ROOT) not in sys.path:
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
from utils.cache import _reset_cache_for_tests
|
||||
from utils.cache.applications import (
|
||||
_build_variants,
|
||||
get_application_defaults,
|
||||
@@ -25,6 +24,7 @@ from utils.cache.applications import (
|
||||
from utils.cache.applications import (
|
||||
_load_variants_overrides as _load_yaml_variant_list,
|
||||
)
|
||||
from utils.cache.reset import _reset_cache_for_tests
|
||||
from utils.roles.mapping import (
|
||||
ROLE_FILE_META_SERVER,
|
||||
ROLE_FILE_META_SERVICES,
|
||||
|
||||
+20
-24
@@ -2,8 +2,8 @@
|
||||
|
||||
Pins the public API (`get_user_defaults`, `get_merged_users`) plus the
|
||||
internal helpers that only this module owns: `_load_user_defs`,
|
||||
`_build_users`, `_validate_forwards`, `_compute_reserved_usernames`, `_load_store_users`,
|
||||
`_resolve_tokens_file`, `_hydrate_users_tokens`, `_merge_users`,
|
||||
`_build_users`, `_validate_forwards`, `_compute_reserved_usernames`,
|
||||
`_hydrate_users_tokens`, `_merge_users`,
|
||||
`_materialize_domain_label_reservations`. Module name is `test_users_module`
|
||||
to disambiguate from the existing `tests/unit/python/plugins/lookup/test_users.py`
|
||||
which targets the lookup plugin.
|
||||
@@ -18,11 +18,11 @@ import unittest.mock as mock
|
||||
from collections import OrderedDict
|
||||
from pathlib import Path
|
||||
|
||||
from utils.cache import _reset_cache_for_tests
|
||||
from utils.cache import base as cache_base
|
||||
from utils.cache import tokens as cache_tokens
|
||||
from utils.cache import users as cache_users
|
||||
from utils.cache.carrier import USERS_RENDERED_FACT, merged_users_cache_key
|
||||
from utils.cache.users import store as cache_users_store
|
||||
from utils.cache.reset import _reset_cache_for_tests
|
||||
from utils.cache.yaml import dump_yaml_str
|
||||
from utils.domains.default_primary import default_domain_primary
|
||||
from utils.roles.mapping import ROLE_FILE_META_SERVICES, ROLE_FILE_META_USERS
|
||||
@@ -345,7 +345,7 @@ class TestResolveTokensFile(unittest.TestCase):
|
||||
sentinel.write_text("users: {}\n", encoding="utf-8")
|
||||
cache_base.DEFAULT_TOKENS_FILE = sentinel
|
||||
try:
|
||||
result = cache_users._resolve_tokens_file(variables={})
|
||||
result = cache_tokens.resolve_tokens_file(variables={})
|
||||
self.assertEqual(result, sentinel)
|
||||
finally:
|
||||
cache_base.DEFAULT_TOKENS_FILE = previous
|
||||
@@ -354,7 +354,7 @@ class TestResolveTokensFile(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
explicit = Path(tmp) / "tokens.yml"
|
||||
explicit.write_text("users: {}\n", encoding="utf-8")
|
||||
result = cache_users._resolve_tokens_file(
|
||||
result = cache_tokens.resolve_tokens_file(
|
||||
variables={"FILE_TOKENS": str(explicit)}
|
||||
)
|
||||
self.assertEqual(result, explicit)
|
||||
@@ -362,8 +362,8 @@ class TestResolveTokensFile(unittest.TestCase):
|
||||
|
||||
class TestLoadStoreUsers(unittest.TestCase):
|
||||
def test_missing_path_returns_empty(self):
|
||||
self.assertEqual(cache_users._load_store_users(None), {})
|
||||
self.assertEqual(cache_users._load_store_users(""), {})
|
||||
self.assertEqual(cache_tokens.load_store_users(None), {})
|
||||
self.assertEqual(cache_tokens.load_store_users(""), {})
|
||||
|
||||
def test_yaml_users_block_passes_through(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
@@ -372,7 +372,7 @@ class TestLoadStoreUsers(unittest.TestCase):
|
||||
dump_yaml_str({"users": {"alice": {"tokens": {"x": "y"}}}}),
|
||||
encoding="utf-8",
|
||||
)
|
||||
result = cache_users._load_store_users(path)
|
||||
result = cache_tokens.load_store_users(path)
|
||||
self.assertEqual(result, {"alice": {"tokens": {"x": "y"}}})
|
||||
|
||||
|
||||
@@ -574,9 +574,7 @@ class TestGetMergedUsersCarrierFact(unittest.TestCase):
|
||||
return {
|
||||
"inventory_hostname": host,
|
||||
"users": {"foo": {"email": "foo@example.org"}},
|
||||
cache_users_store.STORE_FACT: {
|
||||
"foo": {"tokens": {"web-app-foo": "minted"}}
|
||||
},
|
||||
cache_tokens.STORE_FACT: {"foo": {"tokens": {"web-app-foo": "minted"}}},
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
@@ -650,7 +648,7 @@ class TestGetMergedUsersCarrierFact(unittest.TestCase):
|
||||
roles = _seed_minimal_user_role(Path(tmp))
|
||||
variables = self._variables()
|
||||
self._park(roles, variables, {"foo": {"carried": True}})
|
||||
variables[cache_users_store.STORE_FACT] = {
|
||||
variables[cache_tokens.STORE_FACT] = {
|
||||
"foo": {"tokens": {"web-app-foo": "rotated"}}
|
||||
}
|
||||
merged, renders = self._merged(roles, variables)
|
||||
@@ -667,7 +665,7 @@ class TestGetMergedUsersCarrierFact(unittest.TestCase):
|
||||
encoding="utf-8",
|
||||
)
|
||||
variables = self._variables()
|
||||
del variables[cache_users_store.STORE_FACT]
|
||||
del variables[cache_tokens.STORE_FACT]
|
||||
variables["FILE_TOKENS"] = str(tokens)
|
||||
carried = self._park(roles, variables, {"foo": {"carried": True}})
|
||||
return roles, variables, tokens, carried
|
||||
@@ -692,7 +690,7 @@ class TestGetMergedUsersCarrierFact(unittest.TestCase):
|
||||
roles, variables, _, carried = self._park_from_the_tokens_file(
|
||||
Path(tmp), "minted"
|
||||
)
|
||||
variables[cache_users_store.STORE_FACT] = {
|
||||
variables[cache_tokens.STORE_FACT] = {
|
||||
"foo": {"tokens": {"web-app-foo": "minted"}}
|
||||
}
|
||||
merged, renders = self._merged(roles, variables)
|
||||
@@ -749,8 +747,8 @@ class TestStoreSignature(unittest.TestCase):
|
||||
@staticmethod
|
||||
def _signature(store: dict) -> tuple:
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
return cache_users._store_signature(
|
||||
{cache_users_store.STORE_FACT: store}, Path(tmp) / "tokens.yml"
|
||||
return cache_tokens.store_signature(
|
||||
{cache_tokens.STORE_FACT: store}, Path(tmp) / "tokens.yml"
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@@ -764,9 +762,9 @@ class TestStoreSignature(unittest.TestCase):
|
||||
tokens_file = Path(tmp) / "tokens.yml"
|
||||
tokens_file.write_text(dump_yaml_str({"users": store}), encoding="utf-8")
|
||||
self.assertEqual(
|
||||
cache_users._store_signature({}, tokens_file),
|
||||
cache_users._store_signature(
|
||||
{cache_users_store.STORE_FACT: store}, tokens_file
|
||||
cache_tokens.store_signature({}, tokens_file),
|
||||
cache_tokens.store_signature(
|
||||
{cache_tokens.STORE_FACT: store}, tokens_file
|
||||
),
|
||||
)
|
||||
|
||||
@@ -774,10 +772,8 @@ class TestStoreSignature(unittest.TestCase):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
absent = Path(tmp) / "tokens.yml"
|
||||
self.assertEqual(
|
||||
cache_users._store_signature({}, absent),
|
||||
cache_users._store_signature(
|
||||
{cache_users_store.STORE_FACT: {}}, absent
|
||||
),
|
||||
cache_tokens.store_signature({}, absent),
|
||||
cache_tokens.store_signature({cache_tokens.STORE_FACT: {}}, absent),
|
||||
)
|
||||
|
||||
def test_fields_and_padding_the_hydration_ignores_keep_the_signature(self):
|
||||
|
||||
Reference in new issue
Block a user