From 814c8ca96b4d514ccd6162050a9652986b54df00 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Wed, 16 Jan 2019 16:38:32 +0100 Subject: [PATCH] validation value when set value --- tiramisu_json_api/api.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tiramisu_json_api/api.py b/tiramisu_json_api/api.py index c620fe4..df44d37 100644 --- a/tiramisu_json_api/api.py +++ b/tiramisu_json_api/api.py @@ -8,6 +8,11 @@ from .setting import undefined from .i18n import _ + +TYPE = {'boolean': bool, + 'number': int, + 'string': str} + class Option: # fake Option (IntOption, StrOption, ...) def __init__(self, @@ -237,6 +242,11 @@ class TiramisuOptionValue(_Value): return self.schema['enum'] def set(self, value): + if self.schema['type'] == 'choice': + if value not in self.schema['enum']: + raise Exception('value {} is not in {}'.format(value, self.schema['enum'])) + elif not isinstance(value, TYPE[self.schema['type']]): + raise Exception('value {} is not a valid {} '.format(value, self.schema['type'])) self.config.modify_value(self.path, self.index, value,