Skip to content

Commit dd4c66a

Browse files
Merge pull request #643 from zkan/add_more_tests_to_increase_code_coverage
Add test to increase test coverage on config.py
2 parents d1cc74a + 2ba4666 commit dd4c66a

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

test/test_config.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,48 @@ def setUp(self):
1515
def test_initialization(self):
1616
endpoint = '/inbound'
1717
port = 5000
18-
debug_mode = True
19-
keys = ['from',
20-
'attachments',
21-
'headers',
22-
'text',
23-
'envelope',
24-
'to',
25-
'html',
26-
'sender_ip',
27-
'attachment-info',
28-
'subject',
29-
'dkim',
30-
'SPF',
31-
'charsets',
32-
'content-ids',
33-
'spam_report',
34-
'spam_score',
35-
'email']
18+
keys = [
19+
'from',
20+
'attachments',
21+
'headers',
22+
'text',
23+
'envelope',
24+
'to',
25+
'html',
26+
'sender_ip',
27+
'attachment-info',
28+
'subject',
29+
'dkim',
30+
'SPF',
31+
'charsets',
32+
'content-ids',
33+
'spam_report',
34+
'spam_score',
35+
'email',
36+
]
3637
host = 'http://127.0.0.1:5000/inbound'
37-
self.assertTrue(debug_mode, self.config.debug_mode)
38-
self.assertTrue(endpoint, self.config.endpoint)
39-
self.assertTrue(host, self.config.host)
40-
self.assertTrue(port, self.config.port)
38+
39+
self.assertTrue(self.config.debug_mode)
40+
self.assertEqual(self.config.endpoint, endpoint)
41+
self.assertEqual(self.config.host, host)
42+
self.assertEqual(self.config.port, port)
4143
for key in keys:
4244
self.assertTrue(key in self.config.keys)
4345

44-
def test_init_environment(self):
46+
def test_init_environment_should_set_env_from_dotenv(self):
4547
config_file = sendgrid.helpers.inbound.config.__file__
4648
env_file_path = os.path.abspath(os.path.dirname(config_file)) + '/.env'
4749
with open(env_file_path, 'w') as f:
4850
f.write('RANDOM_VARIABLE=RANDOM_VALUE')
4951
Config()
5052
os.remove(env_file_path)
51-
self.assertEqual('RANDOM_VALUE', os.environ['RANDOM_VARIABLE'])
53+
self.assertEqual(os.environ['RANDOM_VARIABLE'], 'RANDOM_VALUE')
54+
55+
def test_init_environment_should_not_set_env_if_format_is_invalid(self):
56+
config_file = sendgrid.helpers.inbound.config.__file__
57+
env_file_path = os.path.abspath(os.path.dirname(config_file)) + '/.env'
58+
with open(env_file_path, 'w') as f:
59+
f.write('RANDOM_VARIABLE=RANDOM_VALUE=ANOTHER_RANDOM_VALUE')
60+
Config()
61+
os.remove(env_file_path)
62+
self.assertIsNone(os.environ.get('RANDOM_VARIABLE'))

0 commit comments

Comments
 (0)