예제 #1
0
 def test_serializer_outputs_expected_schema(self):
     experiment = ExperimentFactory(pref_type=Experiment.PREF_TYPE_STR)
     variant = ExperimentVariantFactory.create(experiment=experiment)
     serializer = ExperimentRecipeVariantSerializer(variant)
     self.assertDictEqual(
         serializer.data,
         {"ratio": variant.ratio, "slug": variant.slug, "value": variant.value},
     )
예제 #2
0
    def test_serializer_outputs_expected_int_val(self):
        experiment = ExperimentFactory(pref_type=Experiment.PREF_TYPE_INT)
        variant = ExperimentVariantFactory.create(experiment=experiment,
                                                  value="28")
        serializer = ExperimentRecipeVariantSerializer(variant)

        self.assertEqual(type(serializer.data["value"]), int)
        self.assertEqual(serializer.data, {
            "ratio": variant.ratio,
            "slug": variant.slug,
            "value": 28
        })
예제 #3
0
 def test_serializer_outputs_expected_schema_with_json_str(self):
     experiment = ExperimentFactory(pref_type=Experiment.PREF_TYPE_JSON_STR)
     serializer = ExperimentRecipePrefArgumentsSerializer(experiment)
     self.assertDictEqual(
         serializer.data,
         {
             "preferenceBranchType": experiment.pref_branch,
             "slug": experiment.recipe_slug,
             "experimentDocumentUrl": experiment.experiment_url,
             "preferenceName": experiment.pref_name,
             "preferenceType": "string",
             "branches": [
                 ExperimentRecipeVariantSerializer(variant).data
                 for variant in experiment.variants.all()
             ],
         },
     )