Added tests for entry point

This commit is contained in:
japrogramer 2017-07-26 16:11:07 -05:00
parent 209afd5c47
commit 43d8b661b8
2 changed files with 34 additions and 2 deletions

View File

@ -14,7 +14,7 @@ import psycopg2
import time import time
def exports(list=None): def exports(**kwargs):
"""Useful environment variables """Useful environment variables
:list: TODO :list: TODO
""" """
@ -25,7 +25,6 @@ def pingpost():
""" """
This is the function that actually trys to connect This is the function that actually trys to connect
to postgres to postgres
""" """
try: try:
if os.environ['POSTGRES_USER']: if os.environ['POSTGRES_USER']:

View File

@ -0,0 +1,33 @@
from unittest.mock import patch, PropertyMock
import unittest
import entrypoint
class TestEntrypoint(unittest.TestCase):
"""
We test that the entry point script works.
"""
def setUp(self):
self.prop = 'test'
def test_exports(self):
with patch.dict(entrypoint.os.environ, {'newkey': 'newvalue'}, clear=True):
entrypoint.exports()
self.assertTrue(entrypoint.os.environ['REDIS_URL'])
self.assertTrue(entrypoint.os.environ['CELERY_BROKER_URL'])
self.assertTrue(entrypoint.os.environ['newkey'])
@patch('entrypoint.psycopg2.connect')
def test_pingpost(self, mockConn):
"""
We must assert that psycopg2 conn is called
"""
with patch.dict(entrypoint.os.environ, {
'POSTGRES_USER': 'newvalue',
'POSTGRES_PASSWORD': 'test'}, clear=True):
entrypoint.main(('dir',))
self.assertTrue(mockConn.called)
if __name__ == '__main__':
unittest.main()