Skip to content

Commit

Permalink
feat(nimbus): Update to mozilla-nimbus-schemas 2024.11.5
Browse files Browse the repository at this point in the history
Because:

- we now have strict and lax schemas for Desktop Nimbus Experiments and
  a separate schema for SDK Nimbus Experiments in mozilla-nimbus-schemas
  v2024.11.4; and
- the updated Desktop schema now has the correct feature placeholder
  feature ID

This commit:

- updates us to mozilla-nimbus-schemas v2024.11.5; and
- updates our tests to use the appropriate schema validators in tests

Fixes #11745
  • Loading branch information
brennie committed Nov 13, 2024
1 parent d2dfb06 commit 74440db
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
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

@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

0 comments on commit 74440db

Please sign in to comment.