Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to increase test coverage on config.py #643

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,37 +15,48 @@ def setUp(self):
def test_initialization(self):
endpoint = '/inbound'
port = 5000
debug_mode = True
keys = ['from',
'attachments',
'headers',
'text',
'envelope',
'to',
'html',
'sender_ip',
'attachment-info',
'subject',
'dkim',
'SPF',
'charsets',
'content-ids',
'spam_report',
'spam_score',
'email']
keys = [
'from',
'attachments',
'headers',
'text',
'envelope',
'to',
'html',
'sender_ip',
'attachment-info',
'subject',
'dkim',
'SPF',
'charsets',
'content-ids',
'spam_report',
'spam_score',
'email',
]
host = 'http://127.0.0.1:5000/inbound'
self.assertTrue(debug_mode, self.config.debug_mode)
self.assertTrue(endpoint, self.config.endpoint)
self.assertTrue(host, self.config.host)
self.assertTrue(port, self.config.port)

self.assertTrue(self.config.debug_mode)
self.assertEqual(self.config.endpoint, endpoint)
self.assertEqual(self.config.host, host)
self.assertEqual(self.config.port, port)
for key in keys:
self.assertTrue(key in self.config.keys)

def test_init_environment(self):
def test_init_environment_should_set_env_from_dotenv(self):
config_file = sendgrid.helpers.inbound.config.__file__
env_file_path = os.path.abspath(os.path.dirname(config_file)) + '/.env'
with open(env_file_path, 'w') as f:
f.write('RANDOM_VARIABLE=RANDOM_VALUE')
Config()
os.remove(env_file_path)
self.assertEqual('RANDOM_VALUE', os.environ['RANDOM_VARIABLE'])
self.assertEqual(os.environ['RANDOM_VARIABLE'], 'RANDOM_VALUE')

def test_init_environment_should_not_set_env_if_format_is_invalid(self):
config_file = sendgrid.helpers.inbound.config.__file__
env_file_path = os.path.abspath(os.path.dirname(config_file)) + '/.env'
with open(env_file_path, 'w') as f:
f.write('RANDOM_VARIABLE=RANDOM_VALUE=ANOTHER_RANDOM_VALUE')
Config()
os.remove(env_file_path)
self.assertIsNone(os.environ.get('RANDOM_VARIABLE'))