-
Notifications
You must be signed in to change notification settings - Fork 60
/
test_config_get_bool.py
81 lines (70 loc) · 2.19 KB
/
test_config_get_bool.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Test the get_get_bool_env_var function"""
import os
import unittest
from unittest.mock import patch
from config import get_bool_env_var
class TestEnv(unittest.TestCase):
"""Test the get_bool_env_var function"""
@patch.dict(
os.environ,
{
"TEST_BOOL": "true",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_true(self):
"""Test that gets a boolean environment variable that exists and is true"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertTrue(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "false",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_false(self):
"""Test that gets a boolean environment variable that exists and is false"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertFalse(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "nope",
},
clear=True,
)
def test_get_bool_env_var_that_exists_and_is_false_due_to_invalid_value(self):
"""Test that gets a boolean environment variable that exists and is false
due to an invalid value
"""
result = get_bool_env_var("TEST_BOOL", False)
self.assertFalse(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "false",
},
clear=True,
)
def test_get_bool_env_var_that_does_not_exist_and_default_value_returns_true(self):
"""Test that gets a boolean environment variable that does not exist
and default value returns: true
"""
result = get_bool_env_var("DOES_NOT_EXIST", True)
self.assertTrue(result)
@patch.dict(
os.environ,
{
"TEST_BOOL": "true",
},
clear=True,
)
def test_get_bool_env_var_that_does_not_exist_and_default_value_returns_false(self):
"""Test that gets a boolean environment variable that does not exist
and default value returns: false
"""
result = get_bool_env_var("DOES_NOT_EXIST", False)
self.assertFalse(result)
if __name__ == "__main__":
unittest.main()