|
1 |
| -from unittest.mock import ANY |
| 1 | +from unittest.mock import ANY, MagicMock |
2 | 2 |
|
| 3 | +from openfeature.evaluation_context import EvaluationContext |
3 | 4 | from openfeature.flag_evaluation import FlagEvaluationDetails, FlagType
|
4 |
| -from openfeature.hook import HookContext |
| 5 | +from openfeature.hook import Hook, HookContext |
5 | 6 | from openfeature.hook.hook_support import (
|
6 | 7 | after_all_hooks,
|
7 | 8 | after_hooks,
|
@@ -37,6 +38,23 @@ def test_before_hooks_run_before_method(mock_hook):
|
37 | 38 | mock_hook.before.assert_called_with(hook_context=hook_context, hints=hook_hints)
|
38 | 39 |
|
39 | 40 |
|
| 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 | + |
40 | 58 | def test_after_hooks_run_after_method(mock_hook):
|
41 | 59 | # Given
|
42 | 60 | hook_context = HookContext("flag_key", FlagType.BOOLEAN, True, "")
|
|
0 commit comments