Add nfdeployment handlers
[pti/o2.git] / helm_sdk / tests / test_utils.py
1 ########
2 # Copyright (c) 2019 Cloudify Platform Ltd. All rights reserved
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #        http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 #    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 #    * See the License for the specific language governing permissions and
14 #    * limitations under the License.
15
16 import unittest
17
18 from helm_sdk.exceptions import CloudifyHelmSDKError
19 from helm_sdk.utils import (
20     prepare_parameter,
21     prepare_set_parameters,
22     validate_no_collisions_between_params_and_flags)
23
24
25 class TestUtils(unittest.TestCase):
26
27     def test_prepare_parameter(self):
28         param_dict = {'name': 'param1'}
29         self.assertEqual(prepare_parameter(param_dict), '--param1')
30         param_dict.update({'value': 'value1'})
31         self.assertEqual(prepare_parameter(param_dict), '--param1=value1')
32
33     def test_prepare_set_parameters(self):
34         set_no_val = [{'name': 'x'}]
35         with self.assertRaisesRegexp(
36                 CloudifyHelmSDKError,
37                 "\"set\" parameter name or value is missing"):
38             prepare_set_parameters(set_no_val)
39
40         with self.assertRaisesRegexp(
41                 CloudifyHelmSDKError,
42                 "\"set\" parameter name or value is missing"):
43             set_no_name = [{'value': 'y'}]
44             prepare_set_parameters(set_no_name)
45         # Now set_dict_no_val is a valid set parameter dictionary
46         valid_set_list = [{'name': 'x', 'value': 'y'}]
47         self.assertEqual(prepare_set_parameters(valid_set_list),
48                          ['--set', 'x=y'])
49
50     def test_validate_no_collisions_between_params_and_flags(self):
51         fake_flags = [{'name': 'kube-apiserver', 'value': 'https://0.0.0.0'}]
52         with self.assertRaisesRegexp(CloudifyHelmSDKError,
53                                      "Please do not pass"):
54             validate_no_collisions_between_params_and_flags(fake_flags)
55         fake_flags = [{'name': 'debug'}]
56         self.assertEqual(
57             validate_no_collisions_between_params_and_flags(fake_flags),
58             None)
59         fake_flags = []
60         self.assertEqual(
61             validate_no_collisions_between_params_and_flags(fake_flags),
62             None)