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 ##############################################################################
13 from yardstick.cmd.commands.env import EnvCommand
16 class EnvCommandTestCase(unittest.TestCase):
18 @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
19 @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
20 def test_do_influxdb(self, check_status_mock, start_async_task_mock):
23 self.assertTrue(start_async_task_mock.called)
24 self.assertTrue(check_status_mock.called)
26 @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
27 @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
28 def test_do_grafana(self, check_status_mock, start_async_task_mock):
31 self.assertTrue(start_async_task_mock.called)
32 self.assertTrue(check_status_mock.called)
34 @mock.patch('yardstick.cmd.commands.env.EnvCommand._start_async_task')
35 @mock.patch('yardstick.cmd.commands.env.EnvCommand._check_status')
36 def test_do_prepare(self, check_status_mock, start_async_task_mock):
39 self.assertTrue(start_async_task_mock.called)
40 self.assertTrue(check_status_mock.called)
42 @mock.patch('yardstick.cmd.commands.env.HttpClient.post')
43 def test_start_async_task(self, post_mock):
44 data = {'action': 'createGrafanaContainer'}
45 EnvCommand()._start_async_task(data)
46 self.assertTrue(post_mock.called)
48 @mock.patch('yardstick.cmd.commands.env.HttpClient.get')
49 @mock.patch('yardstick.cmd.commands.env.EnvCommand._print_status')
50 def test_check_status(self, print_mock, get_mock):
51 task_id = str(uuid.uuid4())
52 get_mock.return_value = {'status': 2, 'result': 'error'}
53 status = EnvCommand()._check_status(task_id, 'hello world')
54 self.assertEqual(status, 2)
56 def test_print_status(self):
58 EnvCommand()._print_status('hello', 'word')
59 except Exception as e:
60 self.assertIsInstance(e, IndexError)
67 if __name__ == '__main__':