Пример #1
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=[],
        )

        # 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,
            "platform": experiment.platform,
            "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_name": experiment.public_name,
            "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()
            ],
        }

        self.assertEqual(set(serializer.data.keys()), set(expected_data.keys()))
        self.assertEqual(serializer.data, expected_data)
Пример #2
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")
Пример #3
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",
        )
Пример #4
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",
        )
Пример #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.assertEqual(
            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)
Пример #6
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.assertEqual(
            serialized_preferences[experiment.pref_name],
            {
                "preferenceBranchType":
                experiment.pref_branch,
                "preferenceType":
                PrefTypeField().to_representation(experiment.pref_type),
                "preferenceValue":
                variant.value,
            },
        )
Пример #7
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_name": experiment.public_name,
            "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)
Пример #8
0
 def test_json_field(self):
     field = PrefTypeField()
     self.assertEqual(
         field.to_representation(Experiment.PREF_TYPE_JSON_STR),
         Experiment.PREF_TYPE_STR,
     )
Пример #9
0
    def test_serializer_outputs_expected_schema(self):
        country1 = CountryFactory(code="CA", name="Canada")
        locale1 = LocaleFactory(code="da", name="Danish")
        experiment = ExperimentFactory.create(locales=[locale1], countries=[country1])

        related_exp = ExperimentFactory.create()
        experiment.related_to.add(related_exp)

        serializer = ChangeLogSerializer(experiment)

        risk_tech_description = experiment.risk_technical_description
        # ensure expected_data has "string" if pref_type is json string
        pref_type = PrefTypeField().to_representation(experiment.pref_type)
        expected_data = {
            "type": experiment.type,
            "owner": experiment.owner.id,
            "name": experiment.name,
            "short_description": experiment.short_description,
            "related_work": experiment.related_work,
            "related_to": [related_exp.id],
            "proposed_start_date": str(experiment.proposed_start_date),
            "proposed_duration": experiment.proposed_duration,
            "proposed_enrollment": experiment.proposed_enrollment,
            "design": experiment.design,
            "addon_experiment_id": experiment.addon_experiment_id,
            "addon_release_url": experiment.addon_release_url,
            "pref_name": experiment.pref_name,
            "pref_type": pref_type,
            "pref_branch": experiment.pref_branch,
            "public_name": experiment.public_name,
            "public_description": experiment.public_description,
            "population_percent": "{0:.4f}".format(experiment.population_percent),
            "firefox_min_version": experiment.firefox_min_version,
            "firefox_max_version": experiment.firefox_max_version,
            "firefox_channel": experiment.firefox_channel,
            "client_matching": experiment.client_matching,
            "locales": [{"code": "da", "name": "Danish"}],
            "countries": [{"code": "CA", "name": "Canada"}],
            "platform": experiment.platform,
            "objectives": experiment.objectives,
            "analysis": experiment.analysis,
            "analysis_owner": experiment.analysis_owner.id,
            "survey_required": experiment.survey_required,
            "survey_urls": experiment.survey_urls,
            "survey_instructions": experiment.survey_instructions,
            "engineering_owner": experiment.engineering_owner,
            "bugzilla_id": experiment.bugzilla_id,
            "normandy_slug": experiment.normandy_slug,
            "normandy_id": experiment.normandy_id,
            "data_science_bugzilla_url": experiment.data_science_bugzilla_url,
            "feature_bugzilla_url": experiment.feature_bugzilla_url,
            "risk_partner_related": experiment.risk_partner_related,
            "risk_brand": experiment.risk_brand,
            "risk_fast_shipped": experiment.risk_fast_shipped,
            "risk_confidential": experiment.risk_confidential,
            "risk_release_population": experiment.risk_release_population,
            "risk_revenue": experiment.risk_revenue,
            "risk_data_category": experiment.risk_data_category,
            "risk_external_team_impact": experiment.risk_external_team_impact,
            "risk_telemetry_data": experiment.risk_telemetry_data,
            "risk_ux": experiment.risk_ux,
            "risk_security": experiment.risk_security,
            "risk_revision": experiment.risk_revision,
            "risk_technical": experiment.risk_technical,
            "risk_technical_description": risk_tech_description,
            "risks": experiment.risks,
            "testing": experiment.testing,
            "test_builds": experiment.test_builds,
            "qa_status": experiment.qa_status,
            "review_science": experiment.review_science,
            "review_engineering": experiment.review_engineering,
            "review_qa_requested": experiment.review_qa_requested,
            "review_intent_to_ship": experiment.review_intent_to_ship,
            "review_bugzilla": experiment.review_bugzilla,
            "review_qa": experiment.review_qa,
            "review_relman": experiment.review_relman,
            "review_advisory": experiment.review_advisory,
            "review_legal": experiment.review_legal,
            "review_ux": experiment.review_ux,
            "review_security": experiment.review_security,
            "review_vp": experiment.review_vp,
            "review_data_steward": experiment.review_data_steward,
            "review_comms": experiment.review_comms,
            "review_impacted_teams": experiment.review_impacted_teams,
            "variants": [
                ExperimentVariantSerializer(variant).data
                for variant in experiment.variants.all()
            ],
            "results_url": experiment.results_url,
            "results_initial": experiment.results_initial,
            "results_lessons_learned": experiment.results_lessons_learned,
            "rollout_playbook": experiment.rollout_playbook,
            "rollout_type": experiment.rollout_type,
        }

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

        self.assertEqual(serializer.data, expected_data)