Debian Codegraph @

config_tempest/tests/test_profile.py

raw
1 # Copyright 2018 Red Hat, Inc.
2 # All Rights Reserved.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # 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, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16 from unittest import mock
17
18 from config_tempest import profile
19 from config_tempest.tests.base import BaseConfigTempestTest
20
21
22 class TestProfile(BaseConfigTempestTest):
23
24 def test_convert_remove_append(self):
25 in_data = {
26 'section.key1': 'value1',
27 'section.key2': 'value1,value2'
28 }
29 expected = [
30 'section.key1=value1',
31 'section.key2=value1,value2'
32 ]
33 out_data = profile._convert_remove_append(in_data)
34 self.assertCountEqual(expected, out_data)
35
36 @mock.patch('config_tempest.profile._read_yaml_file')
37 def test_read_profile_file(self, mock_read_yaml):
38 profile_data = {
39 'create': True,
40 'overrides': {
41 'auth.use_dynamic_credentials': True
42 },
43 'append': {
44 'network-feature-enabled.api_extensions': 'ext',
45 'identity-feature-enabled.api_extensions': ['ext1', 'ext2'],
46 'compute-feature-enabled.api_extensions': 'ext3,ext4'
47 },
48 'remove': {
49 'network-feature-enabled.api_extensions': 'dvr',
50 'identity-feature-enabled.api_extensions': ['dvr1', 'dvr2'],
51 'compute-feature-enabled.api_extensions': 'dvr3,dvr4'
52 },
53 'network-id': 'network_id',
54 'out': './etc/tempest.conf'
55 }
56 mock_read_yaml.return_value = profile_data
57 ret_dict = profile.read_profile_file('path')
58 expected = {
59 'create': True,
60 'remove': [
61 'network-feature-enabled.api_extensions=dvr',
62 'identity-feature-enabled.api_extensions=dvr1,dvr2',
63 'compute-feature-enabled.api_extensions=dvr3,dvr4'
64 ],
65 'network-id': 'network_id',
66 'overrides': [('auth', 'use_dynamic_credentials', 'True')],
67 'append': [
68 'network-feature-enabled.api_extensions=ext',
69 'identity-feature-enabled.api_extensions=ext1,ext2',
70 'compute-feature-enabled.api_extensions=ext3,ext4'
71 ],
72 'out': './etc/tempest.conf'
73 }
74 for key in ['create', 'network-id', 'out']:
75 self.assertEqual(expected[key], ret_dict[key])
76 for key in ['remove', 'overrides', 'append']:
77 self.assertListEqual(sorted(expected[key]), sorted(ret_dict[key]))