From 63825b16cf80daabfc76dbccd1e6d6b762adbb1f Mon Sep 17 00:00:00 2001 From: Tom Carrio Date: Sat, 29 Oct 2022 01:58:29 -0400 Subject: [PATCH] test: add unit tests to assert hook_hints are called in hooks Signed-off-by: Tom Carrio --- tests/hooks/test_hook_support.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/hooks/test_hook_support.py b/tests/hooks/test_hook_support.py index fe906cd..e398445 100644 --- a/tests/hooks/test_hook_support.py +++ b/tests/hooks/test_hook_support.py @@ -7,26 +7,31 @@ from open_feature.hooks.hook_support import ( before_hooks, error_hooks, ) +from unittest.mock import ANY def test_error_hooks_run_error_method(mock_hook): # Given hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "") + hook_hints = MappingProxyType(dict()) # When - error_hooks(FlagType.BOOLEAN, hook_context, Exception, [mock_hook], {}) + error_hooks(FlagType.BOOLEAN, hook_context, Exception, [mock_hook], hook_hints) # Then mock_hook.supports_flag_value_type.assert_called_once() mock_hook.error.assert_called_once() + mock_hook.error.assert_called_with(hook_context, ANY, hook_hints) def test_before_hooks_run_before_method(mock_hook): # Given hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "") + hook_hints = MappingProxyType(dict()) # When - before_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], {}) + before_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints) # Then mock_hook.supports_flag_value_type.assert_called_once() mock_hook.before.assert_called_once() + mock_hook.error.assert_called_with(hook_context, hook_hints) def test_after_hooks_run_after_method(mock_hook): @@ -35,20 +40,24 @@ def test_after_hooks_run_after_method(mock_hook): flag_evaluation_details = FlagEvaluationDetails( hook_context.flag_key, "val", "unknown" ) + hook_hints = MappingProxyType(dict()) # When after_hooks( - FlagType.BOOLEAN, hook_context, flag_evaluation_details, [mock_hook], {} + FlagType.BOOLEAN, hook_context, flag_evaluation_details, [mock_hook], hook_hints ) # Then mock_hook.supports_flag_value_type.assert_called_once() mock_hook.after.assert_called_once() + mock_hook.error.assert_called_with(hook_context, flag_evaluation_details, hook_hints) def test_finally_after_hooks_run_finally_after_method(mock_hook): # Given hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "") + hook_hints = MappingProxyType(dict()) # When - after_all_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], {}) + after_all_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints) # Then mock_hook.supports_flag_value_type.assert_called_once() mock_hook.finally_after.assert_called_once() + mock_hook.error.assert_called_with(hook_context, hook_hints)