1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
9 from __future__ import absolute_import
14 from yardstick.cmd.commands.env import EnvCommand
17 class EnvCommandTestCase(unittest.TestCase):
19 @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
20 @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
21 def test_do_influxdb(self, check_status_mock, start_async_task_mock):
24 start_async_task_mock.assert_called_once()
25 check_status_mock.assert_called_once()
27 @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
28 @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
29 def test_do_grafana(self, check_status_mock, start_async_task_mock):
32 start_async_task_mock.assert_called_once()
33 check_status_mock.assert_called_once()
35 @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
36 @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
37 def test_do_prepare(self, check_status_mock, start_async_task_mock):
40 start_async_task_mock.assert_called_once()
41 check_status_mock.assert_called_once()
43 @mock.patch('yardstick.cmd.commands.env.HttpClient.post')
44 def test_start_async_task(self, post_mock):
45 data = {'action': 'create_grafana'}
46 EnvCommand()._start_async_task(data)
47 post_mock.assert_called_once()
49 @mock.patch('yardstick.cmd.commands.env.HttpClient.get')
50 @mock.patch('yardstick.cmd.commands.env.EnvCommand._print_status')
51 def test_check_status(self, print_mock, get_mock):
52 # pylint: disable=unused-argument
53 # NOTE(ralonsoh): the pylint exception must be removed. The mocked
54 # command call must be tested.
55 task_id = str(uuid.uuid4())
56 get_mock.return_value = {'status': 2, 'result': 'error'}
57 status = EnvCommand()._check_status(task_id, 'hello world')
58 self.assertEqual(status, 2)
60 def test_print_status(self):
62 EnvCommand()._print_status('hello', 'word')
63 except Exception as e: # pylint: disable=broad-except
64 # NOTE(ralonsoh): try to reduce the scope of this exception.
65 self.assertIsInstance(e, IndexError)