def test_preference_experiments_unique_branch_values(self): action = ActionFactory(name="preference-experiment") arguments = { "slug": "test", "branches": [ { "slug": "a", "value": "unique" }, { "slug": "b", "value": "duplicate" }, { "slug": "c", "value": "duplicate" }, ], } with pytest.raises(serializers.ValidationError) as exc_info: action.validate_arguments(arguments, RecipeRevisionFactory()) error = action.errors["duplicate_branch_value"] assert exc_info.value.detail == { "arguments": { "branches": { 2: { "value": error } } } }
def test_unique_branch_slugs(self): action = ActionFactory(name="multi-preference-experiment") arguments = MultiPreferenceExperimentArgumentsFactory( branches=[{"slug": "unique"}, {"slug": "duplicate"}, {"slug": "duplicate"}], ) with pytest.raises(serializers.ValidationError) as exc_info: action.validate_arguments(arguments, RecipeRevisionFactory()) error = action.errors["duplicate_branch_slug"] assert exc_info.value.detail == {"arguments": {"branches": {2: {"slug": error}}}}
def test_it_works(self): action = ActionFactory(name="nothing special") # does not raise an exception action.validate_arguments({}, RecipeRevisionFactory())
def create_revision(self, *args, **kwargs): return RecipeRevisionFactory(*args, **kwargs)