Skip to content

Commit 91f9858

Browse files
committed
test: add unit test for evaluation context merging in before_hooks
Signed-off-by: Federico Bond <federicobond@gmail.com>
1 parent 2399568 commit 91f9858

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

tests/hook/test_hook_support.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from unittest.mock import ANY
1+
from unittest.mock import ANY, MagicMock
22

3+
from openfeature.evaluation_context import EvaluationContext
34
from openfeature.flag_evaluation import FlagEvaluationDetails, FlagType
4-
from openfeature.hook import HookContext
5+
from openfeature.hook import Hook, HookContext
56
from openfeature.hook.hook_support import (
67
after_all_hooks,
78
after_hooks,
@@ -37,6 +38,23 @@ def test_before_hooks_run_before_method(mock_hook):
3738
mock_hook.before.assert_called_with(hook_context=hook_context, hints=hook_hints)
3839

3940

41+
def test_before_hooks_merges_evaluation_contexts():
42+
# Given
43+
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
44+
hook_1 = MagicMock(spec=Hook)
45+
hook_1.before.return_value = EvaluationContext("foo", {"key_1": "val_1"})
46+
hook_2 = MagicMock(spec=Hook)
47+
hook_2.before.return_value = EvaluationContext("bar", {"key_2": "val_2"})
48+
hook_3 = MagicMock(spec=Hook)
49+
hook_3.before.return_value = None
50+
51+
# When
52+
context = before_hooks(FlagType.BOOLEAN, hook_context, [hook_1, hook_2, hook_3])
53+
54+
# Then
55+
assert context == EvaluationContext("bar", {"key_1": "val_1", "key_2": "val_2"})
56+
57+
4058
def test_after_hooks_run_after_method(mock_hook):
4159
# Given
4260
hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")

0 commit comments

Comments
 (0)