Merge "heat: convert open to context manager"
[yardstick.git] / tests / unit / apiserver / utils / test_common.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 from __future__ import absolute_import
10 import unittest
11
12 from api.utils import common
13
14
15 class TranslateToStrTestCase(unittest.TestCase):
16
17     def test_translate_to_str_unicode(self):
18         input_str = u'hello'
19         output_str = common.translate_to_str(input_str)
20
21         result = 'hello'
22         self.assertEqual(result, output_str)
23
24     def test_translate_to_str_dict_list_unicode(self):
25         input_str = {
26             u'hello': {u'hello': [u'world']}
27         }
28         output_str = common.translate_to_str(input_str)
29
30         result = {
31             'hello': {'hello': ['world']}
32         }
33         self.assertEqual(result, output_str)
34
35
36 class GetCommandListTestCase(unittest.TestCase):
37
38     def test_get_command_list_no_opts(self):
39         command_list = ['a']
40         opts = {}
41         args = 'b'
42         output_list = common.get_command_list(command_list, opts, args)
43
44         result_list = ['a', 'b']
45         self.assertEqual(result_list, output_list)
46
47     def test_get_command_list_with_opts_args(self):
48         command_list = ['a']
49         opts = {
50             'b': 'c',
51             'task-args': 'd'
52         }
53         args = 'e'
54
55         output_list = common.get_command_list(command_list, opts, args)
56
57         result_list = ['a', 'e', '--b', '--task-args', 'd']
58         self.assertEqual(result_list, output_list)
59
60
61 def main():
62     unittest.main()
63
64
65 if __name__ == '__main__':
66     main()