add tests for utils module
parent
649fb7d6a6
commit
923c8305ae
|
@ -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.'),
|
||||
)
|
|
@ -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
|
Loading…
Reference in New Issue