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 self.assertTrue(start_async_task_mock.called)
25 self.assertTrue(check_status_mock.called)
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 self.assertTrue(start_async_task_mock.called)
33 self.assertTrue(check_status_mock.called)
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 self.assertTrue(start_async_task_mock.called)
41 self.assertTrue(check_status_mock.called)
43 @mock.patch('yardstick.cmd.commands.env.HttpClient.post')
44 def test_start_async_task(self, post_mock):
45 data = {'action': 'createGrafanaContainer'}
46 EnvCommand()._start_async_task(data)
47 self.assertTrue(post_mock.called)
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 task_id = str(uuid.uuid4())
53 get_mock.return_value = {'status': 2, 'result': 'error'}
54 status = EnvCommand()._check_status(task_id, 'hello world')
55 self.assertEqual(status, 2)
57 def test_print_status(self):
59 EnvCommand()._print_status('hello', 'word')
60 except Exception as e:
61 self.assertIsInstance(e, IndexError)
68 if __name__ == '__main__':