|
5 | 5 | from concurrent.futures import ThreadPoolExecutor |
6 | 6 | from unittest.mock import MagicMock |
7 | 7 |
|
8 | | -from openfeature.track import TrackingEventDetails |
9 | 8 | import pytest |
10 | 9 |
|
11 | 10 | from openfeature import api |
12 | | -from openfeature.api import add_hooks, clear_hooks, get_client, set_evaluation_context, set_provider, set_transaction_context |
| 11 | +from openfeature.api import ( |
| 12 | + add_hooks, |
| 13 | + clear_hooks, |
| 14 | + get_client, |
| 15 | + set_evaluation_context, |
| 16 | + set_provider, |
| 17 | + set_transaction_context, |
| 18 | +) |
13 | 19 | from openfeature.client import OpenFeatureClient, _typecheck_flag_value |
14 | 20 | from openfeature.evaluation_context import EvaluationContext |
15 | 21 | from openfeature.event import EventDetails, ProviderEvent, ProviderEventDetails |
@@ -625,21 +631,34 @@ def test_client_should_merge_contexts(): |
625 | 631 | assert context.attributes["client_attr"] == "client_value" |
626 | 632 | assert context.attributes["invocation_attr"] == "invocation_value" |
627 | 633 |
|
| 634 | + |
628 | 635 | def test_client_should_track_event(): |
629 | 636 | spy_provider = MagicMock(spec=NoOpProvider) |
630 | 637 | set_provider(spy_provider) |
631 | 638 | client = get_client() |
632 | 639 | client.track(tracking_event_name="test") |
633 | 640 | spy_provider.track.assert_called_once() |
634 | 641 |
|
| 642 | + |
635 | 643 | def test_tracking_merges_evaluation_contexts(): |
636 | 644 | spy_provider = MagicMock(spec=NoOpProvider) |
637 | 645 | api.set_provider(spy_provider) |
638 | 646 | client = get_client() |
639 | 647 | set_evaluation_context(EvaluationContext("id", attributes={"key": "eval_value"})) |
640 | | - set_transaction_context(EvaluationContext("id", attributes={"transaction_attr": "transaction_value"})) |
641 | | - client.track(tracking_event_name="test", evaluation_context=EvaluationContext("id", attributes={"key": "value"})) |
642 | | - spy_provider.track.assert_called_once_with("test", EvaluationContext("id", attributes={"transaction_attr": "transaction_value", "key": "value"}), None) |
| 648 | + set_transaction_context( |
| 649 | + EvaluationContext("id", attributes={"transaction_attr": "transaction_value"}) |
| 650 | + ) |
| 651 | + client.track( |
| 652 | + tracking_event_name="test", |
| 653 | + evaluation_context=EvaluationContext("id", attributes={"key": "value"}), |
| 654 | + ) |
| 655 | + spy_provider.track.assert_called_once_with( |
| 656 | + "test", |
| 657 | + EvaluationContext( |
| 658 | + "id", attributes={"transaction_attr": "transaction_value", "key": "value"} |
| 659 | + ), |
| 660 | + None, |
| 661 | + ) |
643 | 662 |
|
644 | 663 |
|
645 | 664 | def test_should_noop_if_provider_does_not_support_tracking(monkeypatch): |
|
0 commit comments