def test_serializer_outputs_expected_schema_for_multipref(self): experiment = ExperimentFactory.create( name="public name", firefox_min_version="70.0", locales=[LocaleFactory.create()], countries=[CountryFactory.create()], public_description="this is my public description!", recipe_slug="some-random-slug", platforms=[ Experiment.PLATFORM_WINDOWS, Experiment.PLATFORM_MAC, Experiment.PLATFORM_LINUX, ], is_multi_pref=True, ) variant = ExperimentVariant( slug="slug-value", ratio=25, experiment=experiment, is_control=True ) variant.save() pref = VariantPreferencesFactory.create(variant=variant) expected_comment = expected_comment = f"{experiment.client_matching}\n" serializer = ExperimentRecipeSerializer(experiment) self.assertEqual(serializer.data["action_name"], "multi-preference-experiment") self.assertEqual(serializer.data["name"], experiment.name) self.assertEqual(serializer.data["comment"], expected_comment) self.assertEqual( serializer.data["filter_object"], [ FilterObjectBucketSampleSerializer(experiment).data, FilterObjectChannelSerializer(experiment).data, FilterObjectVersionsSerializer(experiment).data, FilterObjectLocaleSerializer(experiment).data, FilterObjectCountrySerializer(experiment).data, ], ) expected_data = { "slug": "some-random-slug", "experimentDocumentUrl": experiment.experiment_url, "userFacingName": "public name", "userFacingDescription": "this is my public description!", "branches": [ { "preferences": { pref.pref_name: { "preferenceBranchType": pref.pref_branch, "preferenceType": pref.pref_type, "preferenceValue": pref.pref_value, } }, "ratio": 25, "slug": "slug-value", } ], } self.assertDictEqual(serializer.data["arguments"], expected_data)
def test_serializer_outputs_expected_schema_for_message(self): experiment = ExperimentFactory.create( type=Experiment.TYPE_MESSAGE, firefox_min_version="70.0", locales=[LocaleFactory.create()], countries=[CountryFactory.create()], public_description="this is my public description!", public_name="public name", normandy_slug="some-random-slug", platforms=[Experiment.PLATFORM_WINDOWS], ) variant = ExperimentVariant(slug="slug-value", ratio=25, experiment=experiment, is_control=True) variant.save() expected_comment = expected_comment = ( f"{experiment.client_matching}\n" f"Platform: ['All Windows']\n") serializer = ExperimentRecipeSerializer(experiment) self.assertEqual(serializer.data["action_name"], "messaging-experiment") self.assertEqual(serializer.data["name"], experiment.name) self.assertEqual(serializer.data["comment"], expected_comment) self.assertEqual( serializer.data["filter_object"], [ FilterObjectBucketSampleSerializer(experiment).data, FilterObjectChannelSerializer(experiment).data, FilterObjectVersionsSerializer(experiment).data, FilterObjectLocaleSerializer(experiment).data, FilterObjectCountrySerializer(experiment).data, ], ) expected_data = { "slug": "some-random-slug", "experimentDocumentUrl": experiment.experiment_url, "userFacingName": "public name", "userFacingDescription": "this is my public description!", "branches": [{ "groups": [], "value": {}, "ratio": 25, "slug": "slug-value" }], } self.assertEqual(serializer.data["arguments"], expected_data)
def test_serializer_outputs_expected_multipref_schema_for_singularpref(self): experiment = ExperimentFactory.create( name="public name", pref_type=Experiment.PREF_TYPE_INT, pref_branch=Experiment.PREF_BRANCH_DEFAULT, firefox_min_version="70.0", locales=[LocaleFactory.create()], countries=[CountryFactory.create()], public_description="this is my public description!", recipe_slug="some-random-slug", platforms=[Experiment.PLATFORM_WINDOWS], ) variant = ExperimentVariant( slug="slug-value", ratio=25, experiment=experiment, value=5 ) variant.save() expected_comment = expected_comment = ( f"{experiment.client_matching}\n" f"Platform: ['All Windows']\n" ) serializer = ExperimentRecipeSerializer(experiment) self.assertEqual(serializer.data["action_name"], "multi-preference-experiment") self.assertEqual(serializer.data["name"], experiment.name) self.assertEqual(serializer.data["comment"], expected_comment) self.assertEqual( serializer.data["filter_object"], [ FilterObjectBucketSampleSerializer(experiment).data, FilterObjectChannelSerializer(experiment).data, FilterObjectVersionsSerializer(experiment).data, FilterObjectLocaleSerializer(experiment).data, FilterObjectCountrySerializer(experiment).data, ], ) expected_data = { "slug": "some-random-slug", "experimentDocumentUrl": experiment.experiment_url, "userFacingName": "public name", "userFacingDescription": "this is my public description!", "branches": [ { "preferences": { experiment.pref_name: { "preferenceBranchType": "default", "preferenceType": Experiment.PREF_TYPE_INT, "preferenceValue": 5, } }, "ratio": 25, "slug": "slug-value", } ], } self.assertDictEqual(serializer.data["arguments"], expected_data)
def test_serializer_outputs_expect_schema_for_branched_addon(self): experiment = ExperimentFactory.create( firefox_min_version="70.0", type=Experiment.TYPE_ADDON, locales=[LocaleFactory.create()], countries=[CountryFactory.create()], public_description="this is my public description!", public_name="public name", normandy_slug="some-random-slug", platforms=[Experiment.PLATFORM_LINUX], ) variant = ExperimentVariant(slug="slug-value", ratio=25, experiment=experiment) variant.save() serializer = ExperimentRecipeSerializer(experiment) self.assertEqual(serializer.data["action_name"], "branched-addon-study") self.assertEqual(serializer.data["name"], experiment.name) expected_comment = f"{experiment.client_matching}\n" f"Platform: ['All Linux']\n" self.assertEqual(serializer.data["comment"], expected_comment) self.assertEqual( serializer.data["filter_object"], [ FilterObjectBucketSampleSerializer(experiment).data, FilterObjectChannelSerializer(experiment).data, FilterObjectVersionsSerializer(experiment).data, FilterObjectLocaleSerializer(experiment).data, FilterObjectCountrySerializer(experiment).data, ], ) self.assertEqual( serializer.data["arguments"], { "slug": "some-random-slug", "userFacingName": "public name", "userFacingDescription": "this is my public description!", "branches": [{ "ratio": 25, "slug": "slug-value", "extensionApiId": None }], }, )