Merge "Yardstick framework concurrent support"
[yardstick.git] / tests / unit / cmd / commands / test_env.py
1 ##############################################################################
2 # Copyright (c) 2016 Huawei Technologies Co.,Ltd and others.
3 #
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 import unittest
10 import mock
11 import uuid
12
13 from yardstick.cmd.commands.env import EnvCommand
14
15
16 class EnvCommandTestCase(unittest.TestCase):
17
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):
21         env = EnvCommand()
22         env.do_influxdb({})
23         self.assertTrue(start_async_task_mock.called)
24         self.assertTrue(check_status_mock.called)
25
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):
29         env = EnvCommand()
30         env.do_grafana({})
31         self.assertTrue(start_async_task_mock.called)
32         self.assertTrue(check_status_mock.called)
33
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):
37         env = EnvCommand()
38         env.do_prepare({})
39         self.assertTrue(start_async_task_mock.called)
40         self.assertTrue(check_status_mock.called)
41
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)
47
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)
55
56     def test_print_status(self):
57         try:
58             EnvCommand()._print_status('hello', 'word')
59         except Exception as e:
60             self.assertIsInstance(e, IndexError)
61
62
63 def main():
64     unittest.main()
65
66
67 if __name__ == '__main__':
68     main()