add tests for utils module

master
Justin Riley 2016-08-02 23:19:04 -04:00
parent 649fb7d6a6
commit 923c8305ae
2 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,33 @@
import sys
import mock
from testfixtures import LogCapture
IPY = mock.MagicMock()
IPY.embed = mock.MagicMock()
IPY_MODULES = {
'IPython': IPY,
}
@mock.patch.dict('sys.modules', IPY_MODULES)
def test_with_ipython():
from onedns import utils
ns = dict(test=True)
utils.shell(local_ns=ns)
IPY.embed.assert_called_once_with(user_ns=ns)
@mock.patch.object(sys, 'path', [])
def test_without_ipython():
from onedns import utils
with LogCapture() as log:
utils.shell()
log.check(
('onedns', 'ERROR',
'Unable to load IPython:\n\nNo module named IPython\n'),
('onedns', 'ERROR',
'Please check that IPython is installed and working.'),
)

View File

@ -0,0 +1,24 @@
import os
import mock
from onedns import utils
ONE_XMLRPC = 'https://controller:2633/RPC2'
def test_get_kwargs_from_dict():
d = dict(ONE_XMLRPC=ONE_XMLRPC)
kwargs = utils.get_kwargs_from_dict(d, prefix='ONE_')
assert kwargs['XMLRPC'] == ONE_XMLRPC
kwargs = utils.get_kwargs_from_dict(d, prefix='ONE_', lower=True)
assert kwargs['xmlrpc'] == ONE_XMLRPC
@mock.patch.dict(os.environ, {'ONE_XMLRPC': ONE_XMLRPC})
def test_get_kwargs_from_env():
kwargs = utils.get_kwargs_from_env(prefix='ONE_')
assert kwargs['XMLRPC'] == ONE_XMLRPC
kwargs = utils.get_kwargs_from_env(prefix='ONE_', lower=True)
assert kwargs['xmlrpc'] == ONE_XMLRPC