mirror of
				https://github.com/kevinveenbirkenbach/computer-playbook.git
				synced 2025-10-31 02:10:05 +00:00 
			
		
		
		
	Optimized filter functions
This commit is contained in:
		| @@ -1,5 +1,3 @@ | ||||
| # tests/unit/test_configuration_filters.py | ||||
|  | ||||
| import unittest | ||||
| import sys | ||||
| import os | ||||
| @@ -15,6 +13,8 @@ from filter_plugins.configuration_filters import ( | ||||
|     is_feature_enabled, | ||||
| ) | ||||
|  | ||||
| from filter_plugins.get_app_conf import AppConfigKeyError | ||||
|  | ||||
|  | ||||
| class TestConfigurationFilters(unittest.TestCase): | ||||
|     def setUp(self): | ||||
| @@ -38,7 +38,8 @@ class TestConfigurationFilters(unittest.TestCase): | ||||
|         self.assertFalse(is_feature_enabled(self.applications, 'nonexistent', 'app1')) | ||||
|  | ||||
|     def test_is_feature_enabled_false_missing_app(self): | ||||
|         self.assertFalse(is_feature_enabled(self.applications, 'oauth2', 'unknown_app')) | ||||
|          with self.assertRaises(Exception): | ||||
|             is_feature_enabled(self.applications, 'oauth2', 'unknown_app') | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     unittest.main() | ||||
| @@ -174,10 +174,10 @@ class TestCspFilters(unittest.TestCase): | ||||
|     def test_build_csp_header_frame_ancestors(self): | ||||
|         """ | ||||
|         frame-ancestors should include the wildcarded SLD+TLD when | ||||
|         'portfolio_iframe' is enabled, and omit it when disabled. | ||||
|         'port-ui-desktop' is enabled, and omit it when disabled. | ||||
|         """ | ||||
|         # Ensure feature enabled and domain set | ||||
|         self.apps['app1']['features']['portfolio_iframe'] = True | ||||
|         self.apps['app1']['features']['port-ui-desktop'] = True | ||||
|         # simulate a subdomain for the application | ||||
|         self.domains['web-app-port-ui'] = ['domain-example.com'] | ||||
|          | ||||
| @@ -189,7 +189,7 @@ class TestCspFilters(unittest.TestCase): | ||||
|         ) | ||||
|  | ||||
|         # Now disable the feature and rebuild | ||||
|         self.apps['app1']['features']['portfolio_iframe'] = False | ||||
|         self.apps['app1']['features']['port-ui-desktop'] = False | ||||
|         header_no = self.filter.build_csp_header(self.apps, 'app1', self.domains, web_protocol='https') | ||||
|         # Should no longer contain the wildcarded sld.tld | ||||
|         self.assertNotIn("*.domain-example.com", header_no) | ||||
|   | ||||
| @@ -4,7 +4,7 @@ import os | ||||
|  | ||||
| sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../../filter_plugins'))) | ||||
|  | ||||
| from get_app_conf import get_app_conf | ||||
| from get_app_conf import get_app_conf, AppConfigKeyError | ||||
| from ansible.errors import AnsibleFilterError | ||||
|  | ||||
| class TestGetAppConf(unittest.TestCase): | ||||
| @@ -99,11 +99,12 @@ class TestGetAppConf(unittest.TestCase): | ||||
|             get_app_conf(apps, "app", "foo[1].bar", strict=True) | ||||
|  | ||||
|     def test_application_id_not_found(self): | ||||
|         """Test with unknown application_id: should raise error in strict mode.""" | ||||
|         with self.assertRaises(AnsibleFilterError): | ||||
|         """Test with unknown application_id: should always raise error now.""" | ||||
|         with self.assertRaises(AppConfigKeyError): | ||||
|             get_app_conf(self.applications, "unknown", "features.foo", strict=True) | ||||
|         # Non-strict: returns False | ||||
|         self.assertFalse(get_app_conf(self.applications, "unknown", "features.foo", strict=False)) | ||||
|         with self.assertRaises(AppConfigKeyError): | ||||
|             get_app_conf(self.applications, "unknown", "features.foo", strict=False) | ||||
|  | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|     unittest.main() | ||||
|   | ||||
| @@ -57,7 +57,7 @@ galaxy_info: | ||||
|             "applications": { | ||||
|                 "portfolio": { | ||||
|                     "features": { | ||||
|                         "portfolio_iframe": True | ||||
|                         "port-ui-desktop": True | ||||
|                     } | ||||
|                 } | ||||
|             }, | ||||
| @@ -90,7 +90,7 @@ galaxy_info: | ||||
|             "applications": { | ||||
|                 "portfolio": { | ||||
|                     "features": { | ||||
|                         "portfolio_iframe": True | ||||
|                         "port-ui-desktop": True | ||||
|                     } | ||||
|                 } | ||||
|             }, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user