Esempio n. 1
0
class SingularPreferenceRecipeValueSerializer(serializers.ModelSerializer):
    preferenceBranchType = serializers.ReadOnlyField(
        source="experiment.pref_branch")
    preferenceType = PrefTypeField(source="experiment.pref_type")
    preferenceValue = PrefValueField(type_field="experiment__pref_type",
                                     value_field="value",
                                     source="*")

    class Meta:
        model = ExperimentVariant
        fields = ("preferenceBranchType", "preferenceType", "preferenceValue")
Esempio n. 2
0
class VariantPreferenceRecipeSerializer(serializers.ModelSerializer):
    preferenceBranchType = serializers.ReadOnlyField(source="pref_branch")
    preferenceType = PrefTypeField(source="pref_type")
    preferenceValue = PrefValueField(type_field="pref_type",
                                     value_field="pref_value",
                                     source="*")

    class Meta:
        list_serializer_class = VariantPreferenceRecipeListSerializer
        model = VariantPreferences
        fields = (
            "preferenceBranchType",
            "preferenceType",
            "preferenceValue",
            "pref_name",
        )
Esempio n. 3
0
class ExperimentRecipePrefArgumentsSerializer(serializers.ModelSerializer):
    preferenceBranchType = serializers.ReadOnlyField(source="pref_branch")
    slug = serializers.ReadOnlyField(source="normandy_slug")
    experimentDocumentUrl = serializers.ReadOnlyField(source="experiment_url")
    preferenceName = serializers.ReadOnlyField(source="pref_name")
    preferenceType = PrefTypeField(source="pref_type")
    branches = ExperimentRecipeVariantSerializer(many=True, source="variants")

    class Meta:
        model = Experiment
        fields = (
            "preferenceBranchType",
            "slug",
            "experimentDocumentUrl",
            "preferenceName",
            "preferenceType",
            "branches",
        )
Esempio n. 4
0
    def test_seriailzer_outputs_expected_schema_for_single_pref_experiment(self):
        experiment = ExperimentFactory.create(
            pref_type=Experiment.PREF_TYPE_JSON_STR, firefox_max_version="70.0"
        )
        variant = ExperimentVariantFactory.create(experiment=experiment)

        serializer = ExperimentRecipeMultiPrefVariantSerializer(variant)

        self.assertEqual(serializer.data["ratio"], variant.ratio)
        self.assertEqual(serializer.data["slug"], variant.slug)

        serialized_preferences = serializer.data["preferences"]
        self.assertDictEqual(
            serialized_preferences[experiment.pref_name],
            {
                "preferenceBranchType": experiment.pref_branch,
                "preferenceType": PrefTypeField().to_representation(experiment.pref_type),
                "preferenceValue": variant.value,
            },
        )
Esempio n. 5
0
    def test_seriailzer_outputs_expected_schema_for_multi_pref_variant(self):
        experiment = ExperimentFactory.create(
            pref_type=Experiment.PREF_TYPE_JSON_STR, is_multi_pref=True
        )
        variant = ExperimentVariantFactory.create(experiment=experiment)
        preference = VariantPreferencesFactory.create(variant=variant)
        serializer = ExperimentRecipeMultiPrefVariantSerializer(variant)

        self.assertEqual(serializer.data["ratio"], variant.ratio)
        self.assertEqual(serializer.data["slug"], variant.slug)

        serialized_preferences = serializer.data["preferences"]
        self.assertDictEqual(
            serialized_preferences[preference.pref_name],
            {
                "preferenceBranchType": preference.pref_branch,
                "preferenceType": PrefTypeField().to_representation(preference.pref_type),
                "preferenceValue": preference.pref_value,
            },
        )
        self.assertEqual(serializer.data["ratio"], variant.ratio)
        self.assertEqual(serializer.data["slug"], variant.slug)
    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)
 def test_json_field(self):
     field = PrefTypeField()
     self.assertEqual(
         field.to_representation(Experiment.PREF_TYPE_JSON_STR),
         Experiment.PREF_TYPE_STR,
     )