Пример #1
0
    def test_list_view_filters_by_status(self):
        pending_experiments = []

        # new experiments should be excluded
        for i in range(2):
            ExperimentFactory.create_with_variants()

        # pending experiments should be included
        for i in range(3):
            experiment = ExperimentFactory.create_with_variants()
            experiment.status = experiment.STATUS_REVIEW
            experiment.save()
            pending_experiments.append(experiment)

        response = self.client.get(reverse("experiments-api-list"),
                                   {"status": Experiment.STATUS_REVIEW})
        self.assertEqual(response.status_code, 200)

        json_data = json.loads(response.content)

        serialized_experiments = ExperimentSerializer(
            Experiment.objects.filter(status=Experiment.STATUS_REVIEW),
            many=True).data

        self.assertEqual(serialized_experiments, json_data)
Пример #2
0
 def test_serializer_countries(self):
     country = CountryFactory()
     experiment = ExperimentFactory.create(countries=[country])
     serializer = ExperimentSerializer(experiment)
     self.assertEqual(serializer.data["countries"], [{
         "code": country.code,
         "name": country.name
     }])
Пример #3
0
 def test_serializer_locales(self):
     locale = LocaleFactory()
     experiment = ExperimentFactory.create(locales=[locale])
     serializer = ExperimentSerializer(experiment)
     self.assertEqual(serializer.data["locales"], [{
         "code": locale.code,
         "name": locale.name
     }])
Пример #4
0
    def test_get_experiment_returns_experiment_info(self):
        user_email = "*****@*****.**"
        experiment = ExperimentFactory.create_with_variants()

        response = self.client.get(
            reverse("experiments-api-detail", kwargs={"slug":
                                                      experiment.slug}),
            **{settings.OPENIDC_EMAIL_HEADER: user_email},
        )

        self.assertEqual(response.status_code, 200)
        json_data = json.loads(response.content)
        serialized_experiment = ExperimentSerializer(experiment).data
        self.assertEqual(serialized_experiment, json_data)
Пример #5
0
    def test_list_view_serializes_experiments(self):
        experiments = []

        for i in range(3):
            experiment = ExperimentFactory.create_with_variants()
            experiments.append(experiment)

        response = self.client.get(reverse("experiments-api-list"))
        self.assertEqual(response.status_code, 200)

        json_data = json.loads(response.content)

        serialized_experiments = ExperimentSerializer(Experiment.objects.all(),
                                                      many=True).data

        self.assertEqual(serialized_experiments, json_data)
Пример #6
0
    def test_serializer_outputs_expected_schema(self):
        experiment = ExperimentFactory.create_with_status(
            Experiment.STATUS_COMPLETE,
            countries=[],
            locales=[],
            normandy_slug="a-normandy-slug",
            normandy_id=123,
            other_normandy_ids=[],
            results_fail_to_launch=False,
            results_failures_notes="failure notes",
            platforms=[Experiment.PLATFORM_LINUX],
        )

        # ensure expected_data has "string" if pref_type is json string
        pref_type = PrefTypeField().to_representation(experiment.pref_type)
        serializer = ExperimentSerializer(experiment)
        expected_data = {
            "client_matching":
            experiment.client_matching,
            "platforms":
            experiment.platforms,
            "end_date":
            JSTimestampField().to_representation(experiment.end_date),
            "experiment_url":
            experiment.experiment_url,
            "firefox_channel":
            experiment.firefox_channel,
            "firefox_min_version":
            experiment.firefox_min_version,
            "firefox_max_version":
            experiment.firefox_max_version,
            "name":
            experiment.name,
            "population":
            experiment.population,
            "population_percent":
            "{0:.4f}".format(experiment.population_percent),
            "pref_branch":
            experiment.pref_branch,
            "pref_name":
            experiment.pref_name,
            "pref_type":
            pref_type,
            "addon_experiment_id":
            experiment.addon_experiment_id,
            "addon_release_url":
            experiment.addon_release_url,
            "proposed_start_date":
            JSTimestampField().to_representation(
                experiment.proposed_start_date),
            "proposed_enrollment":
            experiment.proposed_enrollment,
            "proposed_duration":
            experiment.proposed_duration,
            "public_description":
            experiment.public_description,
            "slug":
            experiment.slug,
            "start_date":
            JSTimestampField().to_representation(experiment.start_date),
            "status":
            Experiment.STATUS_COMPLETE,
            "type":
            experiment.type,
            "normandy_slug":
            experiment.normandy_slug,
            "normandy_id":
            experiment.normandy_id,
            "other_normandy_ids":
            experiment.other_normandy_ids,
            "variants": [
                ExperimentVariantSerializer(variant).data
                for variant in experiment.variants.all()
            ],
            "locales": [],
            "countries": [],
            "changes": [
                ExperimentChangeLogSerializer(change).data
                for change in experiment.changes.all()
            ],
            "results": {
                "results_url": None,
                "results_initial": None,
                "results_lessons_learned": None,
                "results_fail_to_launch": False,
                "results_recipe_errors": None,
                "results_restarts": None,
                "results_low_enrollment": None,
                "results_early_end": None,
                "results_no_usable_data": None,
                "results_failures_notes": "failure notes",
                "results_changes_to_firefox": None,
                "results_data_for_hypothesis": None,
                "results_confidence": None,
                "results_measure_impact": None,
                "results_impact_notes": None,
            },
            "telemetry_event_category":
            experiment.telemetry_event_category,
            "telemetry_event_method":
            experiment.telemetry_event_method,
            "telemetry_event_object":
            experiment.telemetry_event_object,
            "telemetry_event_value":
            experiment.telemetry_event_value,
        }

        self.assertEqual(set(serializer.data.keys()),
                         set(expected_data.keys()))
        self.assertEqual(serializer.data, expected_data)