Exemple #1
0
 def test_invalid_experiment_treatment_branch_requires_description(self):
     experiment = NimbusExperimentFactory.create_with_status(
         NimbusExperiment.Status.DRAFT,
         application=NimbusExperiment.Application.DESKTOP.value,
         feature_config=NimbusFeatureConfigFactory(
             application=NimbusExperiment.Application.DESKTOP.value),
     )
     treatment_branch = NimbusBranchFactory.create(experiment=experiment,
                                                   description="")
     experiment.branches.add(treatment_branch)
     experiment.save()
     serializer = NimbusReadyForReviewSerializer(
         experiment,
         data=NimbusReadyForReviewSerializer(
             experiment,
             context={
                 "user": self.user
             },
         ).data,
         context={"user": self.user},
     )
     self.assertFalse(serializer.is_valid())
     self.assertEqual(
         serializer.errors["treatment_branches"][1],
         ["Description cannot be blank."],
     )
Exemple #2
0
    def test_form_rejects_reference_branch_from_other_experiment(self):
        experiment = NimbusExperimentFactory.create()
        branch = NimbusBranchFactory.create()

        form = NimbusExperimentAdminForm(instance=experiment,
                                         data={"reference_branch": branch.id})
        self.assertFalse(form.is_valid())
        self.assertIn("reference_branch", form.errors)
    def test_form_rejects_invalid_json(self):
        feature_config = NimbusFeatureConfigFactory(schema=self.schema)
        experiment = NimbusExperimentFactory.create(feature_config=feature_config)
        branch = NimbusBranchFactory.create(experiment=experiment)

        form = NimbusBranchAdminForm(
            instance=branch,
            data={"experiment": experiment, "feature_value": "{invalid"},
        )
        self.assertFalse(form.is_valid())
        self.assertIn("feature_value", form.errors)
    def test_form_accepts_valid_feature_value(self):
        feature_config = NimbusFeatureConfigFactory(schema=self.schema)
        experiment = NimbusExperimentFactory.create(feature_config=feature_config)
        branch = NimbusBranchFactory.create(experiment=experiment)

        form = NimbusBranchAdminForm(
            instance=branch,
            data={
                "experiment": experiment,
                "feature_value": json.dumps(
                    {
                        "firstName": "John",
                        "lastName": "Jacob",
                        "age": 3,
                    }
                ),
            },
        )
        self.assertFalse(form.is_valid())
        self.assertNotIn("feature_value", form.errors)
Exemple #5
0
    def test_form_rejects_any_branch_if_no_experiment_provided(self):
        branch = NimbusBranchFactory.create()

        form = NimbusExperimentAdminForm(data={"reference_branch": branch.id})
        self.assertFalse(form.is_valid())
        self.assertIn("reference_branch", form.errors)
 def test_str(self):
     branch = NimbusBranchFactory.create()
     self.assertEqual(str(branch), branch.name)