Skip to content

Commit 21cdc21

Browse files
committed
test: add unit tests to assert hook_hints are called in hooks
1 parent 3313967 commit 21cdc21

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

tests/hooks/test_hook_support.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,31 @@
77
before_hooks,
88
error_hooks,
99
)
10+
from unittest.mock import ANY
1011

1112

1213
def test_error_hooks_run_error_method(mock_hook):
1314
# Given
1415
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
16+
hook_hints = MappingProxyType(dict())
1517
# When
16-
error_hooks(FlagType.BOOLEAN, hook_context, Exception, [mock_hook], {})
18+
error_hooks(FlagType.BOOLEAN, hook_context, Exception, [mock_hook], hook_hints)
1719
# Then
1820
mock_hook.supports_flag_value_type.assert_called_once()
1921
mock_hook.error.assert_called_once()
22+
mock_hook.error.assert_called_with(hook_context, ANY, hook_hints)
2023

2124

2225
def test_before_hooks_run_before_method(mock_hook):
2326
# Given
2427
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
28+
hook_hints = MappingProxyType(dict())
2529
# When
26-
before_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], {})
30+
before_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints)
2731
# Then
2832
mock_hook.supports_flag_value_type.assert_called_once()
2933
mock_hook.before.assert_called_once()
34+
mock_hook.error.assert_called_with(hook_context, hook_hints)
3035

3136

3237
def test_after_hooks_run_after_method(mock_hook):
@@ -35,20 +40,24 @@ def test_after_hooks_run_after_method(mock_hook):
3540
flag_evaluation_details = FlagEvaluationDetails(
3641
hook_context.flag_key, "val", "unknown"
3742
)
43+
hook_hints = MappingProxyType(dict())
3844
# When
3945
after_hooks(
40-
FlagType.BOOLEAN, hook_context, flag_evaluation_details, [mock_hook], {}
46+
FlagType.BOOLEAN, hook_context, flag_evaluation_details, [mock_hook], hook_hints
4147
)
4248
# Then
4349
mock_hook.supports_flag_value_type.assert_called_once()
4450
mock_hook.after.assert_called_once()
51+
mock_hook.error.assert_called_with(hook_context, flag_evaluation_details, hook_hints)
4552

4653

4754
def test_finally_after_hooks_run_finally_after_method(mock_hook):
4855
# Given
4956
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
57+
hook_hints = MappingProxyType(dict())
5058
# When
51-
after_all_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], {})
59+
after_all_hooks(FlagType.BOOLEAN, hook_context, [mock_hook], hook_hints)
5260
# Then
5361
mock_hook.supports_flag_value_type.assert_called_once()
5462
mock_hook.finally_after.assert_called_once()
63+
mock_hook.error.assert_called_with(hook_context, hook_hints)

0 commit comments

Comments
 (0)