Esempio n. 1
0
 def test_serializer_outputs_expected_schema(self):
     country1 = CountryFactory.create(code="ab")
     country2 = CountryFactory.create(code="cd")
     experiment = ExperimentFactory.create(countries=[country1, country2])
     serializer = FilterObjectCountrySerializer(experiment)
     self.assertEqual(serializer.data["type"], "country")
     self.assertEqual(set(serializer.data["countries"]), set(["ab", "cd"]))
Esempio n. 2
0
 def test_serializer_outputs_expected_schema(self):
     country = CountryFactory.create()
     serializer = CountrySerializerMultiSelect(country)
     self.assertEqual(serializer.data, {
         "value": country.id,
         "label": country.name
     })
Esempio n. 3
0
 def test_serializer_outputs_expected_schema_for_addon_experiment(self):
     experiment = ExperimentFactory.create_with_status(
         Experiment.STATUS_SHIP,
         type=Experiment.TYPE_ADDON,
         locales=[LocaleFactory.create()],
         countries=[CountryFactory.create()],
     )
     serializer = ExperimentRecipeSerializer(experiment)
     self.assertEqual(serializer.data["action_name"], "opt-out-study")
     self.assertEqual(serializer.data["name"], experiment.name)
     self.assertEqual(
         serializer.data["comment"], experiment.client_matching
     )
     self.assertEqual(
         serializer.data["filter_object"],
         [
             FilterObjectBucketSampleSerializer(experiment).data,
             FilterObjectChannelSerializer(experiment).data,
             FilterObjectLocaleSerializer(experiment).data,
             FilterObjectCountrySerializer(experiment).data,
         ],
     )
     self.assertEqual(
         serializer.data["arguments"],
         ExperimentRecipeAddonArgumentsSerializer(experiment).data,
     )
Esempio n. 4
0
    def test_serializer_outputs_expected_schema_for_pref_experiment(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_SHIP,
            firefox_min_version="65.0",
            type=Experiment.TYPE_PREF,
            locales=[LocaleFactory.create()],
            countries=[CountryFactory.create()],
            platforms=[Experiment.PLATFORM_MAC],
            profile_age="Existing Profiles Only",
        )
        serializer = ExperimentRecipeSerializer(experiment)
        self.assertEqual(serializer.data["action_name"],
                         "preference-experiment")
        self.assertEqual(serializer.data["name"], experiment.name)
        expected_comment = (f"{experiment.client_matching}\n"
                            f"Platform: ['All Mac']\n"
                            "Profile Age: Existing Profiles Only")
        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"],
            ExperimentRecipePrefArgumentsSerializer(experiment).data,
        )

        self.assertEqual(serializer.data["experimenter_slug"], experiment.slug)
Esempio n. 5
0
    def test_serializer_outputs_expected_schema_for_addon_experiment(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_SHIP,
            firefox_min_version="63.0",
            type=Experiment.TYPE_ADDON,
            locales=[LocaleFactory.create()],
            countries=[CountryFactory.create()],
            platforms=[Experiment.PLATFORM_WINDOWS],
            windows_versions=[Experiment.VERSION_WINDOWS_8],
        )
        serializer = ExperimentRecipeSerializer(experiment)
        self.assertEqual(serializer.data["action_name"], "opt-out-study")
        self.assertEqual(serializer.data["name"], experiment.name)

        expected_comment = (f"{experiment.client_matching}\n"
                            f"Platform: ['All Windows']\n"
                            f"Windows Versions: ['Windows 8']\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"],
            ExperimentRecipeAddonArgumentsSerializer(experiment).data,
        )

        self.assertEqual(serializer.data["experimenter_slug"], experiment.slug)
 def test_serializer_outputs_expected_schema(self):
     country = CountryFactory.create()
     serializer = CountrySerializer(country)
     self.assertEqual(serializer.data, {
         "code": country.code,
         "name": country.name
     })
Esempio n. 7
0
    def test_serializer_outputs_expected_schema_for_pref_experiment(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_SHIP,
            type=Experiment.TYPE_PREF,
            locales=[LocaleFactory.create()],
            countries=[CountryFactory.create()],
        )
        serializer = ExperimentRecipeSerializer(experiment)
        self.assertEqual(serializer.data["action_name"],
                         "preference-experiment")
        self.assertEqual(serializer.data["name"], experiment.name)
        self.assertEqual(serializer.data["comment"],
                         experiment.client_matching)
        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"],
            ExperimentRecipePrefArgumentsSerializer(experiment).data,
        )

        self.assertEqual(serializer.data["experimenter_slug"], experiment.slug)
Esempio n. 8
0
    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 setUp(self):
     super().setUp()
     self.locale = LocaleFactory.create()
     self.country = CountryFactory.create()
     self.experiment = ExperimentFactory.create(
         type=ExperimentConstants.TYPE_PREF,
         locales=[self.locale],
         countries=[self.country],
         population_percent="30.0000",
     )
Esempio n. 10
0
    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
                }],
            },
        )
Esempio n. 11
0
 def setUp(self):
     super().setUp()
     self.locale = LocaleFactory.create()
     self.country = CountryFactory.create()
     self.experiment = ExperimentFactory.create_with_status(
         ExperimentConstants.STATUS_DRAFT,
         type=ExperimentConstants.TYPE_PREF,
         locales=[self.locale],
         countries=[self.country],
         population_percent="30.0000",
         platforms=[ExperimentConstants.PLATFORM_WINDOWS],
         windows_versions=[ExperimentConstants.VERSION_WINDOWS_8],
     )
Esempio n. 12
0
    def test_serializer_outputs_expected_schema_for_windows_versions(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_SHIP,
            firefox_min_version="65.0",
            type=Experiment.TYPE_PREF,
            locales=[LocaleFactory.create()],
            countries=[CountryFactory.create()],
            windows_versions=[Experiment.VERSION_WINDOWS_8],
        )

        serializer = ExperimentRecipeSerializer(experiment)

        self.assertEqual(
            serializer.data["filter_object"],
            [
                FilterObjectBucketSampleSerializer(experiment).data,
                FilterObjectChannelSerializer(experiment).data,
                FilterObjectVersionsSerializer(experiment).data,
                FilterObjectLocaleSerializer(experiment).data,
                FilterObjectCountrySerializer(experiment).data,
            ],
        )
Esempio n. 13
0
    def test_message_experiment_sets_default_locales_countries(self):
        [
            LocaleFactory.create(code=l)
            for l in Experiment.MESSAGE_DEFAULT_LOCALES
        ]
        [
            CountryFactory.create(code=c)
            for c in Experiment.MESSAGE_DEFAULT_COUNTRIES
        ]

        self.data["type"] = Experiment.TYPE_MESSAGE
        form = ExperimentOverviewForm(request=self.request, data=self.data)
        self.assertTrue(form.is_valid())
        experiment = form.save()

        self.assertEqual(
            set(experiment.locales.values_list("code", flat=True)),
            set(Experiment.MESSAGE_DEFAULT_LOCALES),
        )
        self.assertEqual(
            set(experiment.countries.values_list("code", flat=True)),
            set(Experiment.MESSAGE_DEFAULT_COUNTRIES),
        )
Esempio n. 14
0
    def test_serializer_outputs_expected_schema_for_multipref(self):

        experiment = ExperimentFactory.create(
            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,
                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.assertEqual(serializer.data["arguments"], expected_data)
Esempio n. 15
0
    def test_serializer_outputs_expected_multipref_schema_for_singularpref(
            self):

        experiment = ExperimentFactory.create(
            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!",
            public_name="public name",
            normandy_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.assertEqual(serializer.data["arguments"], expected_data)