-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_original_source.py
48 lines (37 loc) · 1.46 KB
/
test_original_source.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""
These tests show that the interface of original SecretsSettingsSource declares features
that are not working:
- env_ignore_empty
- env_parse_none_str
- env_parse_enums
- str_strip_whitespace
"""
from enum import Enum
from typing import Optional
from dirlay import Dir
from pydantic_settings import BaseSettings
from pytest import mark
from pydantic_file_secrets import SettingsConfigDict
class SampleEnum(str, Enum):
TEST = 'test'
class Settings(BaseSettings):
some_str: Optional[str] = None
some_enum: Optional[SampleEnum] = None
@mark.parametrize(
'secrets,conf,expected',
(
({'some_str': ''}, dict(env_ignore_empty=True), {'some_str': ''}),
({'some_str': 'null'}, dict(env_parse_none_str='null'), {'some_str': 'null'}),
({'some_enum': 'test'}, dict(env_parse_enums=False), {'some_enum': SampleEnum.TEST}),
# whitespace is always stripped on secrets
({'some_str': 'value '}, dict(), {'some_str': 'value'}),
({'some_str': 'value '}, dict(str_strip_whitespace=False), {'some_str': 'value'}),
),
) # fmt: skip
def test_not_working(secrets, conf: SettingsConfigDict, expected, tmp_path):
class MySettings(Settings):
model_config = SettingsConfigDict(secrets_dir=tmp_path, **conf)
with Dir(secrets).mktree(tmp_path):
settings = MySettings()
for k, v in expected.items():
assert getattr(settings, k) == v