mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
fix enum validators ignore_extra on settings, fix #13
This commit is contained in:
@@ -34,3 +34,4 @@ class BaseSettings(BaseModel):
|
||||
class Config:
|
||||
env_prefix = 'APP_'
|
||||
validate_all = True
|
||||
ignore_extra = False
|
||||
|
||||
@@ -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
@@ -2,4 +2,4 @@ from distutils.version import StrictVersion
|
||||
|
||||
__all__ = ['VERSION']
|
||||
|
||||
VERSION = StrictVersion('0.0.4')
|
||||
VERSION = StrictVersion('0.0.5')
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user