mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
47 lines
994 B
Python
47 lines
994 B
Python
import pytest
|
|
|
|
from pydantic import BaseSettings, ValidationError
|
|
|
|
|
|
class SimpleSettings(BaseSettings):
|
|
apple: str = ...
|
|
|
|
|
|
def test_sub_env(env):
|
|
env.set('APP_APPLE', 'hello')
|
|
s = SimpleSettings()
|
|
assert s.apple == 'hello'
|
|
|
|
|
|
def test_sub_env_override(env):
|
|
env.set('APP_APPLE', 'hello')
|
|
s = SimpleSettings(apple='goodbye')
|
|
assert s.apple == 'goodbye'
|
|
|
|
|
|
def test_sub_env_missing():
|
|
with pytest.raises(ValidationError) as exc_info:
|
|
SimpleSettings()
|
|
assert """\
|
|
1 error validating input
|
|
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)
|
|
|
|
|
|
def test_env_with_aliass(env):
|
|
class Settings(BaseSettings):
|
|
apple: str = ...
|
|
|
|
class Config:
|
|
fields = {
|
|
'apple': 'BOOM'
|
|
}
|
|
env.set('BOOM', 'hello')
|
|
assert Settings().apple == 'hello'
|