mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-29 06:17:25 +00:00
Work-in-progress commit on the collective code-scanning sidetree, so main can be merged in; the single quality-high gate runs on the integration branch before the pull request. Fixes the CodeQL notes py/import-and-import-from, py/unused-import, py/unused-global-variable, py/empty-except, py/mixed-tuple-returns and py/unused-local-variable across 194 files, and adds one lint per rule under tests/lint/repository/python/ so none of them can come back: test_import_and_import_from, test_unused_imports_hidden_from_ruff, test_unused_global_variables, test_empty_except, test_mixed_tuple_returns, test_unused_local_variables, plus test_modules_import. Accepted security finding: MEDUSA-MP-SCAN-2056 (low) on utils/i18n/client.py:21, an import line matched by a keyword heuristic; operator-confirmed false positive. 🎯 Fix: 85 % 💥 Break: 8 % 💸 Cost: – ⏱️ Time: – 🛡️ Security: 100 % 🏆 Score: 78 🚦 Gate: ⛔ fix 85 % < 90, break 8 % > 5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
59 lines
2.2 KiB
Python
59 lines
2.2 KiB
Python
import unittest
|
|
import unittest.mock
|
|
|
|
from ansible.errors import AnsibleError
|
|
|
|
from plugins.lookup.package_batch import LookupModule
|
|
from utils.packages.schema import PackagesShapeError
|
|
|
|
MODULE = "plugins.lookup.package_batch"
|
|
|
|
|
|
class TestPackageBatchLookup(unittest.TestCase):
|
|
def _run(self, terms, group_names, closure=None, side_effect=None):
|
|
applications = unittest.mock.Mock()
|
|
applications.run.return_value = [{"web-app-x": {}}]
|
|
with (
|
|
unittest.mock.patch(
|
|
f"{MODULE}.lookup_loader.get", return_value=applications
|
|
),
|
|
unittest.mock.patch(
|
|
f"{MODULE}.types_from_group_names", return_value=["server"]
|
|
),
|
|
unittest.mock.patch(
|
|
f"{MODULE}.deploy_closure",
|
|
return_value=closure or {"web-app-x"},
|
|
side_effect=side_effect,
|
|
) as closure_mock,
|
|
unittest.mock.patch(
|
|
f"{MODULE}.batch_ids", return_value=["git"]
|
|
) as ids_mock,
|
|
):
|
|
lookup = LookupModule()
|
|
result = lookup.run(terms, variables={"group_names": group_names})
|
|
return result, closure_mock, ids_mock
|
|
|
|
def test_returns_the_batch_ids_of_the_closure(self):
|
|
result, _closure, ids = self._run([["web-app-x"]], ["web-app-x"])
|
|
self.assertEqual(result, [["git"]])
|
|
self.assertEqual(ids.call_args.args[0], {"web-app-x"})
|
|
|
|
def test_nested_and_scalar_terms_become_one_seed_list(self):
|
|
_result, closure, _ids = self._run([["web-app-x"], "role-b"], ["web-app-x"])
|
|
self.assertEqual(closure.call_args.args[1], ["web-app-x", "role-b"])
|
|
|
|
def test_the_host_groups_select_types_and_gates(self):
|
|
_result, closure, _ids = self._run([["web-app-x"]], ["web-app-x", "servers"])
|
|
self.assertEqual(closure.call_args.kwargs["host_types"], ["server"])
|
|
self.assertEqual(
|
|
closure.call_args.kwargs["group_names"], ["web-app-x", "servers"]
|
|
)
|
|
|
|
def test_a_registry_error_becomes_an_ansible_error(self):
|
|
with self.assertRaises(AnsibleError):
|
|
self._run([["web-app-x"]], [], side_effect=PackagesShapeError("broken"))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|