|
1 | 1 | # coding: utf-8 |
2 | 2 | import os |
3 | 3 | import pytest |
4 | | -from decouple import Config, RepositoryString, UndefinedValueError |
| 4 | +from decouple import Config, RepositoryGoogleSecretManager, UndefinedValueError |
5 | 5 |
|
6 | | -ENVSTRING = ''' |
| 6 | +ENVSTRING = """ |
7 | 7 | KeyTrue=True\nKeyOne=1\nKeyYes=yes |
8 | 8 | KeyY=y |
9 | 9 | KeyOn=on |
|
18 | 18 | # CommentedKey=None |
19 | 19 | KeyWithSpaces = Some Value With Spaces |
20 | 20 | KeyWithQuotes="Quoted Value" |
21 | | -''' |
| 21 | +""" |
22 | 22 |
|
23 | 23 |
|
24 | | -@pytest.fixture(scope='module') |
| 24 | +@pytest.fixture(scope="module") |
25 | 25 | def config(): |
26 | | - return Config(RepositoryString(ENVSTRING)) |
| 26 | + return Config(RepositoryGoogleSecretManager(ENVSTRING)) |
27 | 27 |
|
28 | 28 |
|
29 | 29 | def test_string_comment(config): |
30 | 30 | with pytest.raises(UndefinedValueError): |
31 | | - config('CommentedKey') |
| 31 | + config("CommentedKey") |
32 | 32 |
|
33 | 33 |
|
34 | 34 | def test_string_bool_true(config): |
35 | | - assert config('KeyTrue', cast=bool) |
36 | | - assert config('KeyOne', cast=bool) |
37 | | - assert config('KeyYes', cast=bool) |
38 | | - assert config('KeyY', cast=bool) |
39 | | - assert config('KeyOn', cast=bool) |
| 35 | + assert config("KeyTrue", cast=bool) |
| 36 | + assert config("KeyOne", cast=bool) |
| 37 | + assert config("KeyYes", cast=bool) |
| 38 | + assert config("KeyY", cast=bool) |
| 39 | + assert config("KeyOn", cast=bool) |
40 | 40 |
|
41 | 41 |
|
42 | 42 | def test_string_bool_false(config): |
43 | | - assert not config('KeyFalse', cast=bool) |
44 | | - assert not config('KeyZero', cast=bool) |
45 | | - assert not config('KeyNo', cast=bool) |
46 | | - assert not config('KeyOff', cast=bool) |
47 | | - assert not config('KeyN', cast=bool) |
48 | | - assert not config('KeyEmpty', cast=bool) |
| 43 | + assert not config("KeyFalse", cast=bool) |
| 44 | + assert not config("KeyZero", cast=bool) |
| 45 | + assert not config("KeyNo", cast=bool) |
| 46 | + assert not config("KeyOff", cast=bool) |
| 47 | + assert not config("KeyN", cast=bool) |
| 48 | + assert not config("KeyEmpty", cast=bool) |
49 | 49 |
|
50 | 50 |
|
51 | 51 | def test_string_undefined(config): |
52 | 52 | with pytest.raises(UndefinedValueError): |
53 | | - config('UndefinedKey') |
| 53 | + config("UndefinedKey") |
54 | 54 |
|
55 | 55 |
|
56 | 56 | def test_string_default_none(config): |
57 | | - assert config('UndefinedKey', default=None) is None |
| 57 | + assert config("UndefinedKey", default=None) is None |
58 | 58 |
|
59 | 59 |
|
60 | 60 | def test_string_default_bool(config): |
61 | | - assert not config('UndefinedKey', default=False, cast=bool) |
62 | | - assert config('UndefinedKey', default=True, cast=bool) |
| 61 | + assert not config("UndefinedKey", default=False, cast=bool) |
| 62 | + assert config("UndefinedKey", default=True, cast=bool) |
63 | 63 |
|
64 | 64 |
|
65 | 65 | def test_string_default(config): |
66 | | - assert not config('UndefinedKey', default=False) |
67 | | - assert config('UndefinedKey', default=True) |
| 66 | + assert not config("UndefinedKey", default=False) |
| 67 | + assert config("UndefinedKey", default=True) |
68 | 68 |
|
69 | 69 |
|
70 | 70 | def test_string_default_invalid_bool(config): |
71 | 71 | with pytest.raises(ValueError): |
72 | | - config('UndefinedKey', default='NotBool', cast=bool) |
| 72 | + config("UndefinedKey", default="NotBool", cast=bool) |
73 | 73 |
|
74 | 74 |
|
75 | 75 | def test_string_empty(config): |
76 | | - assert config('KeyEmpty', default=None) == '' |
| 76 | + assert config("KeyEmpty", default=None) == "" |
77 | 77 |
|
78 | 78 |
|
79 | 79 | def test_string_support_space(config): |
80 | | - assert config('KeyWithSpaces') == 'Some Value With Spaces' |
| 80 | + assert config("KeyWithSpaces") == "Some Value With Spaces" |
81 | 81 |
|
82 | 82 |
|
83 | 83 | def test_string_os_environ(config): |
84 | | - os.environ['KeyOverrideByEnv'] = 'This' |
85 | | - assert config('KeyOverrideByEnv') == 'This' |
86 | | - del os.environ['KeyOverrideByEnv'] |
| 84 | + os.environ["KeyOverrideByEnv"] = "This" |
| 85 | + assert config("KeyOverrideByEnv") == "This" |
| 86 | + del os.environ["KeyOverrideByEnv"] |
87 | 87 |
|
88 | 88 |
|
89 | 89 | def test_string_undefined_but_present_in_os_environ(config): |
90 | | - os.environ['KeyOnlyEnviron'] = '' |
91 | | - assert config('KeyOnlyEnviron') == '' |
92 | | - del os.environ['KeyOnlyEnviron'] |
| 90 | + os.environ["KeyOnlyEnviron"] = "" |
| 91 | + assert config("KeyOnlyEnviron") == "" |
| 92 | + del os.environ["KeyOnlyEnviron"] |
93 | 93 |
|
94 | 94 |
|
95 | 95 | def test_string_empty_string_means_false(config): |
96 | | - assert not config('KeyEmpty', cast=bool) |
| 96 | + assert not config("KeyEmpty", cast=bool) |
97 | 97 |
|
98 | 98 |
|
99 | 99 | def test_string_repo_keyerror(config): |
100 | 100 | with pytest.raises(KeyError): |
101 | | - config.repository['UndefinedKey'] |
| 101 | + config.repository["UndefinedKey"] |
102 | 102 |
|
103 | 103 |
|
104 | 104 | def test_string_quoted_value(config): |
105 | | - assert config('KeyWithQuotes') == 'Quoted Value' |
| 105 | + assert config("KeyWithQuotes") == "Quoted Value" |
0 commit comments