-
Notifications
You must be signed in to change notification settings - Fork 470
fix(Admin API): Sort features by overrides #6722
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
Merged
+393
−15
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
194e214
Sort features by segment override
emyller 2f3c4a6
Sort features by identity override
emyller 36917da
Fix sorting based on segment overrides
emyller 520db30
Fix identity URI param
emyller ec88a82
Sort features by **edge** identity overrides
emyller 2c612c9
Trim tests nails
emyller 71738c0
Reorder clicks in e2e tests
emyller 7f74e4a
Improve validation
emyller 41d4509
Fix code positioning
emyller 933a477
Improve type safety
emyller 388a4b4
Merge remote-tracking branch 'github/main' into fix/sort-features-by-…
emyller e9d4f8d
Fix coverage
emyller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
api/tests/unit/edge_api/identities/test_edge_identity_service.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import pytest | ||
| from django.core.exceptions import ObjectDoesNotExist | ||
| from pytest_mock import MockerFixture | ||
|
|
||
| from edge_api.identities.edge_identity_service import ( | ||
| get_overridden_feature_ids_for_edge_identity, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def _mock_ddb_identity_wrapper(mocker: MockerFixture) -> MagicMock: | ||
| return mocker.patch( | ||
| "edge_api.identities.models.EdgeIdentity.dynamo_wrapper", | ||
| ) | ||
|
|
||
|
|
||
| def _make_identity_document( | ||
| *, | ||
| environment_api_key: str, | ||
| identity_features: list[dict], # type: ignore[type-arg] | ||
| ) -> dict: # type: ignore[type-arg] | ||
| return { | ||
| "composite_key": f"{environment_api_key}_test_user", | ||
| "identity_traits": [], | ||
| "identity_features": identity_features, | ||
| "identifier": "test_user", | ||
| "created_date": "2021-09-21T10:12:42.230257+00:00", | ||
| "environment_api_key": environment_api_key, | ||
| "identity_uuid": "59efa2a7-6a45-46d6-b953-a7073a90eacf", | ||
| "django_id": None, | ||
| } | ||
|
|
||
|
|
||
| def test_get_overridden_feature_ids_for_edge_identity__identity_with_overrides__returns_feature_ids( | ||
| _mock_ddb_identity_wrapper: MagicMock, | ||
| ) -> None: | ||
| # Given | ||
| feature_a_id = 101 | ||
| feature_b_id = 202 | ||
| identity_document = _make_identity_document( | ||
| environment_api_key="test_key", | ||
| identity_features=[ | ||
| { | ||
| "feature": { | ||
| "id": feature_a_id, | ||
| "name": "feature_a", | ||
| "type": "STANDARD", | ||
| }, | ||
| "enabled": True, | ||
| "featurestate_uuid": "a7495917-ee57-41d1-a64e-e0697dbc57fb", | ||
| "feature_state_value": None, | ||
| "feature_segment": None, | ||
| "multivariate_feature_state_values": [], | ||
| }, | ||
| { | ||
| "feature": { | ||
| "id": feature_b_id, | ||
| "name": "feature_b", | ||
| "type": "STANDARD", | ||
| }, | ||
| "enabled": False, | ||
| "featurestate_uuid": "b8506028-ff68-42e2-b75f-f1708ecd68fc", | ||
| "feature_state_value": None, | ||
| "feature_segment": None, | ||
| "multivariate_feature_state_values": [], | ||
| }, | ||
| ], | ||
| ) | ||
| _mock_ddb_identity_wrapper.get_item_from_uuid.return_value = identity_document | ||
|
|
||
| # When | ||
| result = get_overridden_feature_ids_for_edge_identity( | ||
| "59efa2a7-6a45-46d6-b953-a7073a90eacf" | ||
| ) | ||
|
|
||
| # Then | ||
| assert result == {feature_a_id, feature_b_id} | ||
| _mock_ddb_identity_wrapper.get_item_from_uuid.assert_called_once_with( | ||
| "59efa2a7-6a45-46d6-b953-a7073a90eacf" | ||
| ) | ||
|
|
||
|
|
||
| def test_get_overridden_feature_ids_for_edge_identity__identity_without_overrides__returns_empty_set( | ||
| _mock_ddb_identity_wrapper: MagicMock, | ||
| ) -> None: | ||
| # Given | ||
| identity_document = _make_identity_document( | ||
| environment_api_key="test_key", | ||
| identity_features=[], | ||
| ) | ||
| _mock_ddb_identity_wrapper.get_item_from_uuid.return_value = identity_document | ||
|
|
||
| # When | ||
| result = get_overridden_feature_ids_for_edge_identity( | ||
| "59efa2a7-6a45-46d6-b953-a7073a90eacf" | ||
| ) | ||
|
|
||
| # Then | ||
| assert result == set() | ||
|
|
||
|
|
||
| def test_get_overridden_feature_ids_for_edge_identity__nonexistent_identity__returns_empty_set( | ||
| _mock_ddb_identity_wrapper: MagicMock, | ||
| ) -> None: | ||
| # Given | ||
| _mock_ddb_identity_wrapper.get_item_from_uuid.side_effect = ObjectDoesNotExist() | ||
|
|
||
| # When | ||
| result = get_overridden_feature_ids_for_edge_identity( | ||
| "59efa2a7-6a45-46d6-b953-a7073a90eacf" | ||
| ) | ||
|
|
||
| # Then | ||
| assert result == set() |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.