-
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
11
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
11 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 fad2328
feat(onboarding): Organisation targeting key for experiment bucketing
khvn26 5dbfaa2
feat(onboarding): Decide the onboarding flow client-side
khvn26 745dda5
Merge remote-tracking branch 'origin/main' into feat/onboarding-org-e…
khvn26 4169bca
chore: Update documentation artefacts
flagsmith-engineering[bot] 47e7017
fix(onboarding): Losing entry decision persisted after fallback routing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("organisations", "0059_use_no_ssrf_url_field"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="organisation", | ||
| name="targeting_key", | ||
| field=models.CharField( | ||
| blank=True, | ||
| help_text=( | ||
| "Flagsmith-on-Flagsmith targeting key. Immutable; org.<id> " | ||
| "is used when unset." | ||
| ), | ||
| max_length=64, | ||
| null=True, | ||
| ), | ||
| ), | ||
| ] |
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
77 changes: 77 additions & 0 deletions
77
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,77 @@ | ||
| 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__org_targeting_key_set__tracks_with_stored_key( | ||
| environment: Environment, | ||
| mock_openfeature_client: MagicMock, | ||
| ) -> None: | ||
| # Given | ||
| organisation = environment.project.organisation | ||
| organisation.targeting_key = "a" * 32 | ||
| organisation.save(update_fields=["targeting_key"]) | ||
|
|
||
| # When | ||
| record_environment_first_evaluation(environment, "flagsmith-python-sdk") | ||
|
|
||
| # Then | ||
| call_args = mock_openfeature_client.track.call_args | ||
| assert call_args.kwargs["evaluation_context"].targeting_key == "a" * 32 | ||
|
|
||
|
|
||
| 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
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.