fix enum validators ignore_extra on settings, fix #13

This commit is contained in:
Samuel Colvin
2017-05-11 22:19:11 +01:00
parent 35add310cc
commit 90a2b6bfe3
5 changed files with 24 additions and 3 deletions
+1
View File
@@ -34,3 +34,4 @@ class BaseSettings(BaseModel):
class Config:
env_prefix = 'APP_'
validate_all = True
ignore_extra = False
+2 -2
View File
@@ -89,11 +89,11 @@ def enum_validator(v, field, **kwargs) -> Enum:
# order is important here, for example: bool is a subclass of int so has to come first, datetime before date same
_VALIDATORS = [
(Enum, [enum_validator]),
(str, [not_none_validator, str_validator, anystr_length_validator]),
(bytes, [not_none_validator, bytes_validator, anystr_length_validator]),
(Enum, [enum_validator]),
(bool, [bool_validator]),
(int, [int, number_size_validator]),
(float, [float, number_size_validator]),
+1 -1
View File
@@ -2,4 +2,4 @@ from distutils.version import StrictVersion
__all__ = ['VERSION']
VERSION = StrictVersion('0.0.4')
VERSION = StrictVersion('0.0.5')
+15
View File
@@ -1,3 +1,4 @@
from enum import Enum
from typing import Dict, List, Union
import pytest
@@ -313,3 +314,17 @@ def test_recursive_lists():
assert len(Model.__fields__['v'].sub_fields[0].sub_fields) == 1
assert Model.__fields__['v'].sub_fields[0].sub_fields[0].sub_fields[1].name == '__v_float'
assert len(Model.__fields__['v'].sub_fields[0].sub_fields[0].sub_fields) == 2
def test_str_enum():
class StrEnum(str, Enum):
a = 'a10'
b = 'b10'
class Model(BaseModel):
v: StrEnum = ...
assert Model(v='a10').v is StrEnum.a
with pytest.raises(ValidationError):
Model(v='different')
+5
View File
@@ -27,3 +27,8 @@ def test_sub_env_missing():
apple:
None is not an allow value (error_type=TypeError track=str)\
""" == str(exc_info.value)
def test_other_setting(env):
with pytest.raises(ValidationError):
SimpleSettings(apple='a', foobar=42)