Ejemplo n.º 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)
Ejemplo n.º 2
0
    def test_serializer_outputs_expected_schema(self):
        experiment = ExperimentFactory.create_with_variants(
            type=ExperimentConstants.TYPE_GENERIC)

        serializer = ExperimentDesignGenericSerializer(experiment)

        self.assertCountEqual(
            serializer.data,
            {
                "design":
                experiment.design,
                "variants": [
                    ExperimentVariantSerializer(variant).data
                    for variant in experiment.variants.all()
                ],
            },
        )
Ejemplo n.º 3
0
    def test_serializer_outputs_expected_schema(self):
        experiment = ExperimentFactory.create_with_variants(
            type=ExperimentConstants.TYPE_ADDON)

        serializer = ExperimentDesignAddonSerializer(experiment)
        self.assertCountEqual(
            serializer.data,
            {
                "addon_release_url":
                experiment.addon_release_url,
                "is_branched_addon":
                False,
                "variants": [
                    ExperimentVariantSerializer(variant).data
                    for variant in experiment.variants.all()
                ],
            },
        )
Ejemplo n.º 4
0
    def test_serializer_outputs_expected_schema(self):
        experiment = ExperimentFactory.create_with_variants(
            type=ExperimentConstants.TYPE_ADDON)
        experiment.is_branched_addon = True
        experiment.save()

        serializer = ExperimentDesignBranchedAddonSerializer(experiment)

        self.assertCountEqual(
            serializer.data,
            {
                "is_branched_addon":
                True,
                "variants": [
                    ExperimentVariantSerializer(variant).data
                    for variant in experiment.variants.all()
                ],
            },
        )
Ejemplo n.º 5
0
    def test_serializer_outputs_expected_schema(self):
        experiment = ExperimentFactory.create_with_variants(
            type=ExperimentConstants.TYPE_PREF)

        serializer = ExperimentDesignPrefSerializer(experiment)

        self.assertCountEqual(
            serializer.data,
            {
                "is_multi_pref":
                False,
                "pref_key":
                experiment.pref_key,
                "pref_type":
                experiment.pref_type,
                "pref_branch":
                experiment.pref_branch,
                "variants": [
                    ExperimentVariantSerializer(variant).data
                    for variant in experiment.variants.all()
                ],
            },
        )
Ejemplo n.º 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_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)
Ejemplo n.º 7
0
    def test_serializer_outputs_expected_schema(self):
        country1 = CountryFactory(code="CA", name="Canada")
        locale1 = LocaleFactory(code="da", name="Danish")
        project = ProjectFactory.create()
        experiment = ExperimentFactory.create(
            locales=[locale1], countries=[country1], projects=[project]
        )

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

        serializer = ChangeLogSerializer(experiment)

        risk_tech_description = experiment.risk_technical_description

        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": experiment.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"}],
            "projects": [{"slug": project.slug}],
            "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_issue_url": experiment.data_science_issue_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,
            "results_fail_to_launch": experiment.results_fail_to_launch,
            "results_recipe_errors": experiment.results_recipe_errors,
            "results_restarts": experiment.results_restarts,
            "results_low_enrollment": experiment.results_low_enrollment,
            "results_early_end": experiment.results_early_end,
            "results_no_usable_data": experiment.results_no_usable_data,
            "results_failures_notes": experiment.results_failures_notes,
            "results_changes_to_firefox": experiment.results_changes_to_firefox,
            "results_data_for_hypothesis": experiment.results_data_for_hypothesis,
            "results_confidence": experiment.results_confidence,
            "results_measure_impact": experiment.results_measure_impact,
            "results_impact_notes": experiment.results_impact_notes,
            "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)
Ejemplo n.º 8
0
    def test_update_change_log_creates_log_with_correct_change(self):

        experiment = ExperimentFactory.create()
        variant = ExperimentVariantFactory.create(
            experiment=experiment,
            ratio=100,
            description="it's a description",
            name="variant name",
        )

        variant_data = {
            "ratio": 100,
            "description": variant.description,
            "name": variant.name,
        }
        changed_values = {
            "variants": {
                "new_value": {
                    "variants": [variant_data]
                },
                "old_value": None,
                "display_name": "Branches",
            }
        }
        ExperimentChangeLog.objects.create(
            experiment=experiment,
            changed_by=UserFactory(),
            old_status=Experiment.STATUS_DRAFT,
            new_status=Experiment.STATUS_DRAFT,
            changed_values=changed_values,
            message="",
        )

        self.assertEqual(experiment.changes.count(), 1)

        change_data = {
            "variants": [{
                "id": variant.id,
                "ratio": 100,
                "description": "some other description",
                "name": "some other name",
                "is_control": False,
            }]
        }
        serializer = ExperimentDesignBaseSerializer(
            instance=experiment,
            data=change_data,
            context={"request": self.request})

        self.assertTrue(serializer.is_valid())
        experiment = serializer.save()

        serializer_variant_data = ExperimentVariantSerializer(variant).data

        self.assertEqual(experiment.changes.count(), 2)
        changed_values = experiment.changes.latest().changed_values

        variant = ExperimentVariant.objects.get(id=variant.id)
        changed_serializer_variant_data = ExperimentVariantSerializer(
            variant).data

        self.assertIn("variants", changed_values)
        self.assertEqual(changed_values["variants"]["old_value"],
                         [serializer_variant_data])
        self.assertEqual(changed_values["variants"]["new_value"],
                         [changed_serializer_variant_data])