def test_proposed_enrollment_end_date_without_start_date_is_None(self):
     experiment = NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.CREATED, )
     self.assertIsNone(experiment.proposed_enrollment_end_date)
 def test_should_timeout(self, expected, timeout, lifecycle):
     with override_settings(KINTO_REVIEW_TIMEOUT=timeout):
         experiment = NimbusExperimentFactory.create_with_lifecycle(
             lifecycle)
         self.assertEqual(experiment.should_timeout, expected)
 def test_should_end_returns_False_before_proposed_end_date(self):
     experiment = NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.LAUNCH_APPROVE_APPROVE,
         proposed_duration=10,
     )
     self.assertFalse(experiment.should_end)
 def test_proposed_end_date_returns_None_for_not_started_experiment(self):
     experiment = NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.CREATED, )
     self.assertIsNone(experiment.proposed_end_date)
Beispiel #5
0
    def test_serializer_outputs_expected_schema_with_feature(self):
        experiment = NimbusExperimentFactory.create_with_lifecycle(
            NimbusExperimentFactory.Lifecycles.ENDING_APPROVE_APPROVE,
            application=NimbusExperiment.Application.DESKTOP,
            firefox_min_version=NimbusExperiment.Version.FIREFOX_83,
            targeting_config_slug=NimbusExperiment.TargetingConfig.ALL_ENGLISH,
            channel=NimbusExperiment.Channel.NIGHTLY,
            primary_outcomes=["foo", "bar", "baz"],
            secondary_outcomes=["quux", "xyzzy"],
        )

        serializer = NimbusExperimentSerializer(experiment)
        experiment_data = serializer.data.copy()
        bucket_data = dict(experiment_data.pop("bucketConfig"))
        branches_data = [dict(b) for b in experiment_data.pop("branches")]

        self.assertDictEqual(
            experiment_data,
            {
                "arguments": {},
                "application": "firefox-desktop",
                "appName": "firefox_desktop",
                "appId": "firefox-desktop",
                "channel": "nightly",
                # DRF manually replaces the isoformat suffix so we have to do the same
                "endDate": experiment.end_date.isoformat().replace("+00:00", "Z"),
                "id": experiment.slug,
                "isEnrollmentPaused": True,
                "proposedDuration": experiment.proposed_duration,
                "proposedEnrollment": experiment.proposed_enrollment,
                "referenceBranch": experiment.reference_branch.slug,
                "schemaVersion": settings.NIMBUS_SCHEMA_VERSION,
                "slug": experiment.slug,
                # DRF manually replaces the isoformat suffix so we have to do the same
                "startDate": experiment.start_date.isoformat().replace("+00:00", "Z"),
                "targeting": (
                    'browserSettings.update.channel == "nightly" '
                    "&& version|versionCompare('83.!') >= 0 "
                    "&& 'app.shield.optoutstudies.enabled'|preferenceValue "
                    "&& localeLanguageCode == 'en'"
                ),
                "userFacingDescription": experiment.public_description,
                "userFacingName": experiment.name,
                "probeSets": [],
                "outcomes": [
                    {"priority": "primary", "slug": "foo"},
                    {"priority": "primary", "slug": "bar"},
                    {"priority": "primary", "slug": "baz"},
                    {"priority": "secondary", "slug": "quux"},
                    {"priority": "secondary", "slug": "xyzzy"},
                ],
                "featureIds": [experiment.feature_config.slug],
            },
        )
        self.assertEqual(
            bucket_data,
            {
                "randomizationUnit": (
                    experiment.bucket_range.isolation_group.randomization_unit
                ),
                "namespace": experiment.bucket_range.isolation_group.namespace,
                "start": experiment.bucket_range.start,
                "count": experiment.bucket_range.count,
                "total": experiment.bucket_range.isolation_group.total,
            },
        )
        self.assertEqual(len(branches_data), 2)
        for branch in experiment.branches.all():
            self.assertIn(
                {
                    "slug": branch.slug,
                    "ratio": branch.ratio,
                    "feature": {
                        "featureId": experiment.feature_config.slug,
                        "enabled": branch.feature_enabled,
                        "value": json.loads(branch.feature_value),
                    },
                },
                branches_data,
            )

        check_schema("experiments/NimbusExperiment", serializer.data)
 def test_exception_for_fetch_jetstream_data(self, mock_delay):
     NimbusExperimentFactory.create_with_lifecycle(
         NimbusExperimentFactory.Lifecycles.ENDING_APPROVE_APPROVE, )
     mock_delay.side_effect = Exception
     with self.assertRaises(Exception):
         tasks.fetch_jetstream_data()
 def test_no_data_fetch_in_loop(self, lifecycle, mock_delay):
     NimbusExperimentFactory.create_with_lifecycle(lifecycle)
     tasks.fetch_jetstream_data()
     mock_delay.assert_not_called()