Esempio n. 1
0
    def test_serializer_rejects_too_long_urls(self):
        data = {
            "addon_release_url": "http://www.example.com" * 100,
            "is_branched_addon": False,
            "variants":
            [self.control_variant_data, self.treatment_variant_data],
        }

        serializer = ExperimentDesignAddonSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertIn("addon_release_url", serializer.errors)
Esempio n. 2
0
    def test_serializer_outputs_dummy_variants_when_no_variants(self):
        experiment = ExperimentFactory.create(
            type=ExperimentConstants.TYPE_ADDON)

        serializer = ExperimentDesignAddonSerializer(experiment)

        self.assertEqual(
            serializer.data,
            {
                "addon_release_url":
                experiment.addon_release_url,
                "is_branched_addon":
                False,
                "variants": [
                    {
                        "description": None,
                        "is_control": True,
                        "name": None,
                        "ratio": 50
                    },
                    {
                        "description": None,
                        "is_control": False,
                        "name": None,
                        "ratio": 50
                    },
                ],
            },
        )
Esempio n. 3
0
    def test_serializer_saves_design_addon_experiment(self):
        experiment = ExperimentFactory.create(
            type=ExperimentConstants.TYPE_ADDON,
            addon_release_url="http://www.example.com",
        )

        data = {
            "addon_release_url": "http://www.example.com",
            "is_branched_addon": False,
            "variants":
            [self.control_variant_data, self.treatment_variant_data],
        }

        serializer = ExperimentDesignAddonSerializer(
            instance=experiment, data=data, context={"request": self.request})
        self.assertTrue(serializer.is_valid())
        self.assertEqual(experiment.changes.count(), 0)
        experiment = serializer.save()

        self.assertEqual(experiment.changes.count(), 1)
Esempio n. 4
0
    def test_get_design_addon_returns_design_info(self):
        user_email = "*****@*****.**"
        experiment = ExperimentFactory.create_with_variants(
            type=ExperimentConstants.TYPE_ADDON
        )

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

        self.assertEqual(response.status_code, 200)
        json_data = json.loads(response.content)

        serialized_experiment = ExperimentDesignAddonSerializer(experiment).data
        self.assertEqual(serialized_experiment, json_data)
Esempio n. 5
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()
                ],
            },
        )