-
Notifications
You must be signed in to change notification settings - Fork 11
fix: omit segments from evaluation context in get_environment_flags #179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
f571af0
13904f6
8f10c42
3bda6aa
10242fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -94,6 +94,41 @@ def test_get_environment_flags_uses_local_environment_when_available( | |||||||||||
| assert all_flags[0].value == "some-value" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def test_get_environment_flags_omits_segments_from_evaluation_context( | ||||||||||||
| mocker: MockerFixture, | ||||||||||||
| flagsmith: Flagsmith, | ||||||||||||
| evaluation_context: SDKEvaluationContext, | ||||||||||||
| ) -> None: | ||||||||||||
| # Given | ||||||||||||
| flagsmith._evaluation_context = evaluation_context | ||||||||||||
| flagsmith.enable_local_evaluation = True | ||||||||||||
| mock_engine = mocker.patch("flagsmith.flagsmith.engine") | ||||||||||||
|
|
||||||||||||
| expected_evaluation_result = { | ||||||||||||
| "flags": { | ||||||||||||
| "some_feature": { | ||||||||||||
| "name": "some_feature", | ||||||||||||
| "enabled": True, | ||||||||||||
| "value": "some-feature-state-value", | ||||||||||||
| "metadata": {"id": 1}, | ||||||||||||
| } | ||||||||||||
| }, | ||||||||||||
| "segments": [], | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| mock_engine.get_evaluation_result.return_value = expected_evaluation_result | ||||||||||||
|
|
||||||||||||
| # When | ||||||||||||
| flagsmith.get_environment_flags() | ||||||||||||
|
|
||||||||||||
| # Then | ||||||||||||
| mock_engine.get_evaluation_result.assert_called_once() | ||||||||||||
| call_args = mock_engine.get_evaluation_result.call_args | ||||||||||||
| context = call_args[1]["context"] # Keyword argument 'context' | ||||||||||||
|
||||||||||||
| # Segments should not be present in the context passed to the engine | ||||||||||||
| assert "segments" not in context | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| @responses.activate() | ||||||||||||
| def test_get_identity_flags_calls_api_when_no_local_environment_no_traits( | ||||||||||||
| flagsmith: Flagsmith, identities_json: str | ||||||||||||
|
|
@@ -191,6 +226,46 @@ def test_get_identity_flags_uses_local_environment_when_available( | |||||||||||
| assert identity_flags[0].value == "some-feature-state-value" | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def test_get_identity_flags_includes_segments_in_evaluation_context( | ||||||||||||
| mocker: MockerFixture, | ||||||||||||
| flagsmith: Flagsmith, | ||||||||||||
| evaluation_context: SDKEvaluationContext, | ||||||||||||
| ) -> None: | ||||||||||||
| # Given | ||||||||||||
| flagsmith._evaluation_context = evaluation_context | ||||||||||||
| flagsmith.enable_local_evaluation = True | ||||||||||||
|
||||||||||||
| mock_engine = mocker.patch("flagsmith.flagsmith.engine") | ||||||||||||
|
||||||||||||
| mock_engine = mocker.patch("flagsmith.flagsmith.engine") | |
| mock_get_evaluation_result = mocker.patch( | |
| "flagsmith.flagsmith.engine.get_evaluation_result", | |
| autospec=True, | |
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 10242fb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use assert_called_once_with method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 10242fb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helps to avoid both the cast and a bytecode loop:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 10242fb