diff options
author | 2017-09-21 09:40:12 +0800 | |
---|---|---|
committer | 2017-09-21 17:07:05 +0800 | |
commit | fc12fe83562430bc406877583111ed725d08edc8 (patch) | |
tree | 22b90d93b501c9f4d73214b453105d4584bde683 /tests/unit/prepare/test_prepare_execute.py | |
parent | 2045ccff6a31ce649cfabc0ba896e9d0d708e3e0 (diff) |
Add some unittest files such as test_nova.py
1.Add test_glance.py, test_neutron.py and test_nova.py unittest
files, and modify the neutron.py to adapt the unittest.
2.Add some unittest functions in test_post_execute.py,
test_deploy.py, test_keystoneauth.py.
3.rename test_prepare_execure.py to test_prepare_execute.py.
Change-Id: Ie0640d133e27c558648416a6a5cf044a00ffa67f
Signed-off-by: zhongjun <zhong.jun@zte.com.cn>
Diffstat (limited to 'tests/unit/prepare/test_prepare_execute.py')
-rw-r--r-- | tests/unit/prepare/test_prepare_execute.py | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/tests/unit/prepare/test_prepare_execute.py b/tests/unit/prepare/test_prepare_execute.py index 03259b93..1831ebc8 100644 --- a/tests/unit/prepare/test_prepare_execute.py +++ b/tests/unit/prepare/test_prepare_execute.py @@ -9,12 +9,14 @@ import os import pytest - +import mock import deploy.prepare.execute from deploy.prepare.execute import ( _set_qemu_compute, _set_default_floating_pool, - _set_trusts_auth + _set_trusts_auth, + _make_dirs, + _write_conf_file ) deploy.prepare.execute.KOLLA_CONF_PATH = '/tmp' @@ -65,3 +67,29 @@ def test__set_trusts_auth(kolla_conf_file_heat_dir): exp_conf_file_2 = os.path.join(kolla_conf_file_heat_dir, 'heat-engine.conf') assert (os.path.isfile(exp_conf_file_1) and os.path.isfile(exp_conf_file_2)) clear_tmp_dir(kolla_conf_file_heat_dir) + + +@pytest.mark.parametrize('ret_isdir', [ + (True), + (False)]) +@mock.patch('os.path.isdir') +@mock.patch('os.makedirs') +def test__make_dirs(mock_makedirs, mock_isdir, ret_isdir): + path = '/tmp/test' + mock_makedirs.return_value = True + mock_isdir.return_value = ret_isdir + _make_dirs(path) + if ret_isdir is False: + mock_makedirs.assert_called_once_with(path, mode=0744) + else: + mock_makedirs.assert_not_called() + + +def test__write_conf_file(tmpdir): + conf_file = os.path.join(tmpdir.dirname, tmpdir.basename, 'test_conf') + conf = 'conf_key1 = value1' + _write_conf_file(conf_file, conf) + with open(conf_file) as f: + data = f.readline().rstrip('\n') + assert data == conf + tmpdir.remove() |