diff options
author | zhifeng.jiang <jiang.zhifeng@zte.com.cn> | 2016-08-20 16:29:26 +0800 |
---|---|---|
committer | zhifeng.jiang <jiang.zhifeng@zte.com.cn> | 2016-08-21 14:23:13 +0800 |
commit | 9b23320f77639f07d2156a4add18fb2f99771520 (patch) | |
tree | 3593b673535bd109fc7031eeb7f00848c5c8b0fb /tests/args_handler_test.py | |
parent | e0482d626cedfb1f30712e82df288454af65c76c (diff) |
Code refactoring cli.py so that it can be reused by restful server.
modification:
Move function in cli.py to args_handler.py
Add unit test for args_handler.py
Add unit test for cli.py
Delete print in driver.py to pass unit test
JIRA:QTIP-99
Change-Id: Ib670d7dff494f3e04cdbe1de5c247d382b1052c1
Signed-off-by: zhifeng.jiang <jiang.zhifeng@zte.com.cn>
Diffstat (limited to 'tests/args_handler_test.py')
-rw-r--r-- | tests/args_handler_test.py | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/args_handler_test.py b/tests/args_handler_test.py new file mode 100644 index 00000000..7f977f21 --- /dev/null +++ b/tests/args_handler_test.py @@ -0,0 +1,35 @@ +############################################################################## +# Copyright (c) 2016 ZTE Corp and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +############################################################################## +import pytest +import mock +import func.args_handler + + +class TestClass: + @pytest.mark.parametrize("test_input, expected", [ + ('./test_cases/zte-pod1/network/iperf_bm.yaml', + ["iperf", + [('1-server', ['10.20.0.23']), ('2-host', ['10.20.0.24'])], + "iperf_bm.yaml", + [('duration', 20), ('protocol', 'tcp'), ('bandwidthGbps', 10)], + [("10.20.0.24", [None]), ("10.20.0.23", [None])], {}]) + ]) + @mock.patch('func.args_handler.Env_setup.call_ping_test') + @mock.patch('func.args_handler.Env_setup.call_ssh_test') + @mock.patch('func.args_handler.Env_setup.update_ansible') + @mock.patch('func.args_handler.SpawnVM') + @mock.patch('func.args_handler.Driver.drive_bench') + def test_prepare_and_run_benchmark_successful(self, mock_driver, mock_sqawn_vm, mock_env_setup_ping, + mock_env_setup_ssh, mock_update_ansible, test_input, expected): + mock_ips = mock.Mock(return_value=["10.20.0.23", "10.20.0.24"]) + func.args_handler.Env_setup.fetch_compute_ips = mock_ips + func.args_handler.prepare_and_run_benchmark(test_input) + call = mock_driver.call_args + call_args, call_kwargs = call + assert sorted(map(sorted, call_args)) == sorted(map(sorted, expected)) |