Skip to content
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

feat(nimbus): Update to mozilla-nimbus-schemas 2024.11.5 #11746

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions experimenter/experimenter/experiments/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ class Application(models.TextChoices):
)
DEMO_APP = (APPLICATION_CONFIG_DEMO_APP.slug, APPLICATION_CONFIG_DEMO_APP.name)

@staticmethod
def is_sdk(application):
return application != Application.DESKTOP
brennie marked this conversation as resolved.
Show resolved Hide resolved

@staticmethod
def is_mobile(application):
return application in (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

from django.conf import settings
from django.test import TestCase
from mozilla_nimbus_schemas.experiments import NimbusExperiment as NimbusExperimentSchema
from mozilla_nimbus_schemas.experiments import (
DesktopAllVersionsNimbusExperiment,
SdkNimbusExperiment,
)
from parameterized import parameterized

from experimenter.base.tests.factories import LocaleFactory
Expand All @@ -21,6 +24,19 @@
class TestNimbusExperimentSerializer(TestCase):
maxDiff = None

@classmethod
def _validate_experiment_schema(
cls,
application: NimbusExperiment.Application,
experiment_data: dict[str, Any],
):
if NimbusExperiment.Application.is_sdk(application):
schema = SdkNimbusExperiment
else:
schema = DesktopAllVersionsNimbusExperiment

schema.model_validate(experiment_data)

def test_expected_schema_with_desktop(self):
locale_en_us = LocaleFactory.create(code="en-US")
application = NimbusExperiment.Application.DESKTOP
Expand Down Expand Up @@ -145,7 +161,7 @@ def test_expected_schema_with_desktop(self):
branches_data,
)

NimbusExperimentSchema.model_validate(serializer.data)
DesktopAllVersionsNimbusExperiment.model_validate(serializer.data)

def test_expected_schema_with_desktop_with_non_default_fxlabs_fields(self):
locale_en_us = LocaleFactory.create(code="en-US")
Expand Down Expand Up @@ -261,7 +277,7 @@ def test_serializers_with_missing_feature_value(self, application):
experiment.save()
serializer = NimbusExperimentSerializer(experiment)
self.assertEqual(serializer.data["branches"][0]["features"], [])
NimbusExperimentSchema.model_validate(serializer.data)
self._validate_experiment_schema(application, serializer.data)

def test_serializers_with_empty_feature_value(self):
application = NimbusExperiment.Application.DESKTOP
Expand All @@ -281,7 +297,7 @@ def test_serializers_with_empty_feature_value(self):
)
serializer = NimbusExperimentSerializer(experiment)
self.assertEqual(serializer.data["branches"][0]["features"][0]["value"], {})
NimbusExperimentSchema.model_validate(serializer.data)
DesktopAllVersionsNimbusExperiment.model_validate(serializer.data)

def test_serializer_with_branch_invalid_feature_value(self):
application = NimbusExperiment.Application.DESKTOP
Expand Down Expand Up @@ -328,7 +344,7 @@ def test_sets_app_id_name_channel_for_application(
NimbusExperiment.APPLICATION_CONFIGS[application].app_name,
)
self.assertEqual(serializer.data["appId"], channel_app_id)
NimbusExperimentSchema.model_validate(serializer.data)
self._validate_experiment_schema(application, serializer.data)

def test_serializer_outputs_targeting(self):
experiment = NimbusExperimentFactory.create_with_lifecycle(
Expand All @@ -339,7 +355,7 @@ def test_serializer_outputs_targeting(self):
)
serializer = NimbusExperimentSerializer(experiment)
self.assertEqual(serializer.data["targeting"], experiment.targeting)
NimbusExperimentSchema.model_validate(serializer.data)
DesktopAllVersionsNimbusExperiment.model_validate(serializer.data)

def test_serializer_outputs_empty_targeting(self):
experiment = NimbusExperimentFactory.create_with_lifecycle(
Expand All @@ -352,7 +368,7 @@ def test_serializer_outputs_empty_targeting(self):

serializer = NimbusExperimentSerializer(experiment)
self.assertEqual(serializer.data["targeting"], "true")
NimbusExperimentSchema.model_validate(serializer.data)
SdkNimbusExperiment.model_validate(serializer.data)

def test_localized_desktop(self):
locale_en_us = LocaleFactory.create(code="en-US")
Expand All @@ -374,7 +390,7 @@ def test_localized_desktop(self):

self.assertIn("localizations", serializer.data)
self.assertEqual(serializer.data["localizations"], json.loads(TEST_LOCALIZATIONS))
NimbusExperimentSchema.model_validate(serializer.data)
DesktopAllVersionsNimbusExperiment.model_validate(serializer.data)

def test_multiple_locales(self):
locale_en_us = LocaleFactory.create(code="en-US")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.conf import settings
from django.test import TestCase
from mozilla_nimbus_schemas.experiments import NimbusExperiment as NimbusExperimentSchema
from parameterized import parameterized

from experimenter.base.tests.factories import LocaleFactory
Expand Down Expand Up @@ -97,8 +96,6 @@ def test_expected_schema_with_desktop(self):
branches_data,
)

NimbusExperimentSchema.model_validate(serializer.data)

def test_expected_schema_with_desktop_with_non_default_fxlabs_fields(self):
locale_en_us = LocaleFactory.create(code="en-US")
application = NimbusExperiment.Application.DESKTOP
Expand Down Expand Up @@ -214,7 +211,6 @@ def test_serializers_with_missing_feature_value(self, application):
experiment.save()
serializer = NimbusExperimentSerializer(experiment)
self.assertEqual(serializer.data["branches"][0]["features"], [])
NimbusExperimentSchema.model_validate(serializer.data)

def test_serializers_with_empty_feature_value(self):
application = NimbusExperiment.Application.DESKTOP
Expand All @@ -234,7 +230,6 @@ def test_serializers_with_empty_feature_value(self):
)
serializer = NimbusExperimentSerializer(experiment)
self.assertEqual(serializer.data["branches"][0]["features"][0]["value"], {})
NimbusExperimentSchema.model_validate(serializer.data)

def test_serializer_with_branch_invalid_feature_value(self):
application = NimbusExperiment.Application.DESKTOP
Expand Down Expand Up @@ -281,7 +276,6 @@ def test_sets_app_id_name_channel_for_application(
NimbusExperiment.APPLICATION_CONFIGS[application].app_name,
)
self.assertEqual(serializer.data["appId"], channel_app_id)
NimbusExperimentSchema.model_validate(serializer.data)

def test_serializer_outputs_targeting(self):
experiment = NimbusExperimentFactory.create_with_lifecycle(
Expand All @@ -292,7 +286,6 @@ def test_serializer_outputs_targeting(self):
)
serializer = NimbusExperimentSerializer(experiment)
self.assertEqual(serializer.data["targeting"], experiment.targeting)
NimbusExperimentSchema.model_validate(serializer.data)

def test_serializer_outputs_empty_targeting(self):
experiment = NimbusExperimentFactory.create_with_lifecycle(
Expand All @@ -305,7 +298,6 @@ def test_serializer_outputs_empty_targeting(self):

serializer = NimbusExperimentSerializer(experiment)
self.assertEqual(serializer.data["targeting"], "true")
NimbusExperimentSchema.model_validate(serializer.data)

def test_localized_desktop(self):
locale_en_us = LocaleFactory.create(code="en-US")
Expand All @@ -328,7 +320,6 @@ def test_localized_desktop(self):

self.assertIn("localizations", serializer.data)
self.assertEqual(serializer.data["localizations"], json.loads(TEST_LOCALIZATIONS))
NimbusExperimentSchema.model_validate(serializer.data)

def test_multiple_locales(self):
locale_en_us = LocaleFactory.create(code="en-US")
Expand Down
10 changes: 5 additions & 5 deletions experimenter/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion experimenter/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ djangorestframework-dataclasses = "^1.3.0"
graphene-django = "^3.2.0"
pyright = "^1.1.291"
django-types = "^0.19.1"
mozilla-nimbus-schemas = "2024.11.2"
mozilla-nimbus-schemas = "2024.11.5"
mozilla-metric-config-parser = "^2024.10.2"
django-redis = "^5.4.0"
fontawesomefree = "6.6.0"
Expand Down