From 5dcc13cb2404988bc6894c550a2adf2087ea7b21 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 11 Jul 2025 20:29:52 +0200 Subject: [PATCH] Added additional unit test to debug html edge cas --- roles/srv-web-7-7-certbot/vars/main.yml | 1 - .../test_applications_filter_for_html.py | 56 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) delete mode 100644 roles/srv-web-7-7-certbot/vars/main.yml create mode 100644 tests/unit/filter_plugins/test_applications_filter_for_html.py diff --git a/roles/srv-web-7-7-certbot/vars/main.yml b/roles/srv-web-7-7-certbot/vars/main.yml deleted file mode 100644 index 87118717..00000000 --- a/roles/srv-web-7-7-certbot/vars/main.yml +++ /dev/null @@ -1 +0,0 @@ -application_id: certbot diff --git a/tests/unit/filter_plugins/test_applications_filter_for_html.py b/tests/unit/filter_plugins/test_applications_filter_for_html.py new file mode 100644 index 00000000..2e29a420 --- /dev/null +++ b/tests/unit/filter_plugins/test_applications_filter_for_html.py @@ -0,0 +1,56 @@ +import os +import yaml +import unittest +from filter_plugins.applications_if_group_and_deps import FilterModule + + +def load_vars(role_name): + # locate project root relative to this test file + tests_dir = os.path.dirname(__file__) + project_root = os.path.abspath(os.path.join(tests_dir, '..', '..', '..')) + vars_path = os.path.join(project_root, 'roles', role_name, 'vars', 'main.yml') + with open(vars_path) as f: + data = yaml.safe_load(f) or {} + return data + + +class TestApplicationsIfGroupAndDeps(unittest.TestCase): + def setUp(self): + self.filter = FilterModule().applications_if_group_and_deps + self.sample_apps = { + 'html': {}, + 'legal': {}, + 'file': {}, + 'asset': {}, + 'portfolio': {}, + 'corporate-identity': {}, + } + + def test_direct_group(self): + result = self.filter(self.sample_apps, ['html']) + self.assertIn('html', result) + self.assertNotIn('legal', result) + + def test_recursive_deps(self): + # html -> depends on none, but corporate-identity pulls in web-svc-legal -> web-svc-html -> legal + result = self.filter(self.sample_apps, ['util-srv-corporate-identity']) + self.assertIn('corporate-identity', result) + self.assertIn('legal', result) # via web-svc-legal + self.assertIn('html', result) # via web-svc-legal -> html + + def test_real_vars_files(self): + # load real vars to get application_id + corp_vars = load_vars('util-srv-corporate-identity') + asset_vars = load_vars('web-svc-asset') + # ensure IDs exist + self.assertIn('application_id', corp_vars) + self.assertIn('application_id', asset_vars) + # run filter + result = self.filter(self.sample_apps, ['util-srv-corporate-identity']) + # ids from vars should appear + self.assertIn(corp_vars['application_id'], result) + self.assertIn(asset_vars['application_id'], result) + + +if __name__ == '__main__': + unittest.main()