-
Notifications
You must be signed in to change notification settings - Fork 556
feat(onboarding): Org-level onboarding experiment events #8242
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
Open
khvn26
wants to merge
6
commits into
main
Choose a base branch
from
feat/onboarding-org-experiment-events
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0ff5f3f
feat(onboarding): Org-level onboarding experiment events
khvn26 1b4d68c
feat(onboarding): Read onboarding variant from the organisation API
khvn26 015d7fd
chore: Update documentation artefacts
flagsmith-engineering[bot] 1935afa
chore: Update documentation artefacts
flagsmith-engineering[bot] c3944b1
build(deps): openfeature-provider-flagsmith 1.0.0 from PyPI
khvn26 9d61fbe
improve test_initialise_provider tests
khvn26 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import typing | ||
|
|
||
| from integrations.flagsmith.client import get_openfeature_client | ||
| from organisations.models import Organisation | ||
|
|
||
| OnboardingVariant = typing.Literal["control", "single_page"] | ||
|
|
||
|
|
||
| def get_onboarding_variant(organisation: Organisation) -> OnboardingVariant: | ||
| details = get_openfeature_client().get_boolean_details( | ||
| "onboarding_quickstart_flow", | ||
| default_value=False, | ||
| evaluation_context=organisation.openfeature_evaluation_context, | ||
| ) | ||
| if not details.value or details.variant == "control": | ||
| return "control" | ||
| return "single_page" |
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
60 changes: 60 additions & 0 deletions
60
api/tests/unit/environments/onboarding/test_unit_environments_onboarding_services.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,60 @@ | ||
| from unittest.mock import MagicMock, Mock | ||
|
|
||
| import pytest | ||
| from django.utils import timezone | ||
| from pytest_mock import MockerFixture | ||
|
|
||
| from environments.models import Environment | ||
| from environments.onboarding.services import record_environment_first_evaluation | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def write_environment_documents(mocker: MockerFixture) -> Mock: | ||
| return mocker.patch.object(Environment, "write_environment_documents") | ||
|
|
||
|
|
||
| @pytest.fixture() | ||
| def mock_openfeature_client(mocker: MockerFixture) -> MagicMock: | ||
| mock_client: MagicMock = mocker.MagicMock() | ||
| mocker.patch( | ||
| "environments.onboarding.services.get_openfeature_client", | ||
| return_value=mock_client, | ||
| ) | ||
| return mock_client | ||
|
|
||
|
|
||
| def test_record_environment_first_evaluation__first_evaluation__tracks_conversion_event( | ||
| environment: Environment, | ||
| mock_openfeature_client: MagicMock, | ||
| ) -> None: | ||
| # Given | ||
| organisation_id = environment.project.organisation_id | ||
|
|
||
| # When | ||
| record_environment_first_evaluation(environment, "flagsmith-python-sdk") | ||
|
|
||
| # Then | ||
| mock_openfeature_client.track.assert_called_once() | ||
| call_args = mock_openfeature_client.track.call_args | ||
| assert call_args.args == ("environment.first_evaluated",) | ||
| assert ( | ||
| call_args.kwargs["evaluation_context"].targeting_key == f"org.{organisation_id}" | ||
| ) | ||
| assert call_args.kwargs["tracking_event_details"].attributes == { | ||
| "sdk_label": "flagsmith-python-sdk", | ||
| } | ||
|
|
||
|
|
||
| def test_record_environment_first_evaluation__already_evaluated__does_not_track( | ||
| environment: Environment, | ||
| mock_openfeature_client: MagicMock, | ||
| ) -> None: | ||
| # Given | ||
| environment.first_evaluated_at = timezone.now() | ||
| environment.save(update_fields=["first_evaluated_at"]) | ||
|
|
||
| # When | ||
| record_environment_first_evaluation(environment, "flagsmith-python-sdk") | ||
|
|
||
| # Then | ||
| mock_openfeature_client.track.assert_not_called() |
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
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.