def test_serializer_outputs_expected_schema_for_str(self):
        experiment = ExperimentFactory.create(
            type=Experiment.TYPE_ROLLOUT,
            normandy_slug="normandy-slug",
            rollout_type=Experiment.TYPE_PREF,
        )

        preference = RolloutPreference(
            pref_type=Experiment.PREF_TYPE_STR,
            pref_name="browser.pref",
            pref_value="a string",
            experiment=experiment,
        )

        preference.save()
        serializer = ExperimentRecipePrefRolloutArgumentsSerializer(experiment)
        serializer_data = serializer.data

        self.assertEqual(serializer_data["slug"], "normandy-slug")

        self.assertDictEqual(
            dict(serializer_data["preferences"][0]),
            {
                "preferenceName": "browser.pref",
                "value": "a string"
            },
        )
    def test_serializer_outputs_expected_schema_for_pref_rollout(self):
        experiment = ExperimentFactory.create(
            countries=[],
            firefox_channel=Experiment.CHANNEL_BETA,
            firefox_max_version="71",
            firefox_min_version="70",
            locales=[],
            name="Experimenter Name",
            recipe_slug="normandy-slug",
            platforms=[Experiment.PLATFORM_WINDOWS],
            population_percent=30.0,
            rollout_type=Experiment.TYPE_PREF,
            slug="experimenter-slug",
            type=Experiment.TYPE_ROLLOUT,
        )
        preference = RolloutPreference(
            pref_name="browser.pref",
            pref_value="true",
            pref_type=Experiment.PREF_TYPE_BOOL,
            experiment=experiment,
        )
        preference.save()
        serializer = ExperimentRecipeSerializer(experiment)

        self.assertDictEqual(
            serializer.data,
            {
                "action_name": "preference-rollout",
                "arguments": {
                    "preferences": [{"preferenceName": "browser.pref", "value": True}],
                    "slug": "normandy-slug",
                },
                "comment": "Geos: US, CA, GB\n"
                'Some "additional" filtering\n'
                "Platform: ['All Windows']\n",
                "experimenter_slug": "experimenter-slug",
                "filter_object": [
                    {
                        "count": 3000,
                        "input": ["normandy.userId"],
                        "start": 0,
                        "total": 10000,
                        "type": "bucketSample",
                    },
                    {"type": "channel", "channels": ["beta"]},
                    {"type": "version", "versions": [70, 71]},
                ],
                "name": "Experimenter Name",
            },
        )
    def test_serializer_outputs_expected_schema_for_multi_pref(self):

        experiment = ExperimentFactory.create(
            type=Experiment.TYPE_ROLLOUT,
            normandy_slug="normandy-slug",
            rollout_type=Experiment.TYPE_PREF,
        )

        preference1 = RolloutPreference(
            pref_type=Experiment.PREF_TYPE_INT,
            pref_name="browser.pref",
            pref_value="4",
            experiment=experiment,
        )

        preference2 = RolloutPreference(
            pref_type=Experiment.PREF_TYPE_STR,
            pref_name="browser.pref1",
            pref_value="a string",
            experiment=experiment,
        )

        preference1.save()
        preference2.save()

        serializer = ExperimentRecipePrefRolloutArgumentsSerializer(experiment)

        serializer_data = serializer.data

        self.assertEqual(serializer_data["slug"], "normandy-slug")

        self.assertCountEqual(
            serializer_data["preferences"],
            [
                {
                    "preferenceName": "browser.pref",
                    "value": 4
                },
                {
                    "preferenceName": "browser.pref1",
                    "value": "a string"
                },
            ],
        )