def test_all_values_are_optional(self):
        data = {}

        serializer = ExperimentTimelinePopSerializer(instance=self.experiment,
                                                     data=data)

        self.assertTrue(serializer.is_valid())
예제 #2
0
    def test_serializer_saves_rollout_playbook_field(self):
        experiment = ExperimentFactory.create(
            type=ExperimentConstants.TYPE_ROLLOUT,
            rollout_playbook=ExperimentConstants.ROLLOUT_PLAYBOOK_LOW_RISK,
            locales=[self.locale],
            countries=[self.country],
            population_percent="30.0000",
            proposed_enrollment=None,
        )

        data = {
            "rollout_playbook": ExperimentConstants.ROLLOUT_PLAYBOOK_HIGH_RISK,
            "countries": [],
            "locales": [],
        }

        serializer = ExperimentTimelinePopSerializer(
            instance=experiment, data=data, context={"request": self.request})

        self.assertTrue(serializer.is_valid())

        experiment = serializer.save()

        self.assertEqual(experiment.rollout_playbook,
                         ExperimentConstants.ROLLOUT_PLAYBOOK_HIGH_RISK)
예제 #3
0
    def test_serializer_rejects_empty_platforms(self):
        data = {"countries": [], "locales": [], "platforms": []}

        serializer = ExperimentTimelinePopSerializer(instance=self.experiment,
                                                     data=data)

        self.assertFalse(serializer.is_valid())
        self.assertIn("platforms", serializer.errors)
예제 #4
0
    def test_serializer_rejects_date_in_past(self):
        data = {
            "proposed_start_date": "2019-2-01",
            "countries": [],
            "locales": []
        }

        serializer = ExperimentTimelinePopSerializer(instance=self.experiment,
                                                     data=data)

        self.assertFalse(serializer.is_valid())
        self.assertIn("proposed_start_date", serializer.errors)
예제 #5
0
    def test_serializer_rejects_enrollment_greater_duration(self):
        data = {
            "countries": [],
            "locales": [],
            "proposed_enrollment": 40,
            "proposed_duration": 30,
        }

        serializer = ExperimentTimelinePopSerializer(instance=self.experiment,
                                                     data=data)

        self.assertFalse(serializer.is_valid())
        self.assertIn("proposed_enrollment", serializer.errors)
예제 #6
0
    def test_serializer_rejects_firefox_min_less_max(self):
        data = {
            "firefox_min_version": "69.0",
            "firefox_max_version": "68.0",
            "countries": [],
            "locales": [],
        }

        serializer = ExperimentTimelinePopSerializer(instance=self.experiment,
                                                     data=data)

        self.assertFalse(serializer.is_valid())
        self.assertIn("firefox_max_version", serializer.errors)
    def test_serializer_saves_values(self):
        country = CountryFactory()
        locale = LocaleFactory()
        countries = [{"value": country.id, "label": country.name}]
        locales = [{"value": locale.id, "label": locale.name}]

        data = {
            "proposed_start_date": datetime.date.today(),
            "proposed_duration": 50,
            "proposed_enrollment": 20,
            "population_percent": 32,
            "firefox_channel": "Nightly",
            "firefox_min_version": "67.0",
            "firefox_max_version": "68.0",
            "countries": countries,
            "locales": locales,
            "platform": "All Windows",
            "client_matching": "matching client.",
        }

        serializer = ExperimentTimelinePopSerializer(
            instance=self.experiment,
            data=data,
            context={"request": self.request})

        self.assertTrue(serializer.is_valid())

        experiment = serializer.save()

        self.assertEqual(experiment.changes.count(), 1)
        self.assertEqual(experiment.proposed_start_date,
                         data["proposed_start_date"])
        self.assertEqual(experiment.proposed_duration,
                         data["proposed_duration"])
        self.assertEqual(experiment.proposed_enrollment,
                         data["proposed_enrollment"])
        self.assertEqual(experiment.population_percent,
                         data["population_percent"])
        self.assertEqual(experiment.firefox_channel, data["firefox_channel"])
        self.assertEqual(experiment.firefox_min_version,
                         data["firefox_min_version"])
        self.assertEqual(experiment.firefox_max_version,
                         data["firefox_max_version"])
        self.assertEqual(experiment.countries.get(), country)
        self.assertEqual(experiment.locales.get(), locale)
        self.assertEqual(experiment.platform, data["platform"])
        self.assertEqual(experiment.client_matching, data["client_matching"])