Add unit test for profile feature
The patch adds a new unit test for profile feature. The patch also converts all overrides values read from profile.yaml to string as this is the data type of overrides. Change-Id: I795b9b900b6274e689ba64b9721fb63e49696dea
This commit is contained in:
parent
3a59007123
commit
d376c37fd6
@ -33,6 +33,18 @@ def _convert_remove_append(options):
|
||||
return converted
|
||||
|
||||
|
||||
def _read_yaml_file(path):
|
||||
"""Read a .yaml file.
|
||||
|
||||
:param path: path to the profile.yaml file
|
||||
:type path: string
|
||||
:return: profile arguments
|
||||
:rtype: dict
|
||||
"""
|
||||
with open(path, 'r') as stream:
|
||||
return yaml.load(stream)
|
||||
|
||||
|
||||
def read_profile_file(path):
|
||||
"""Read python-tempestconf arguments from a .yaml file.
|
||||
|
||||
@ -41,8 +53,7 @@ def read_profile_file(path):
|
||||
:return: profile arguments
|
||||
:rtype: dict
|
||||
"""
|
||||
with open(path, 'r') as stream:
|
||||
profile_args = yaml.load(stream)
|
||||
profile_args = _read_yaml_file(path)
|
||||
# convert overrides, to a list of tuples (s, k, v)
|
||||
overrides = []
|
||||
if 'overrides' in profile_args:
|
||||
@ -51,7 +62,7 @@ def read_profile_file(path):
|
||||
v = profile_args['overrides'][key]
|
||||
if isinstance(v, list):
|
||||
v = ','.join(v)
|
||||
overrides.append((s, k, v))
|
||||
overrides.append((s, k, str(v)))
|
||||
profile_args['overrides'] = overrides
|
||||
# convert remove
|
||||
remove = []
|
||||
|
@ -13,6 +13,8 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import mock
|
||||
|
||||
from config_tempest import profile
|
||||
from config_tempest.tests.base import BaseConfigTempestTest
|
||||
|
||||
@ -30,3 +32,46 @@ class TestProfile(BaseConfigTempestTest):
|
||||
]
|
||||
out_data = profile._convert_remove_append(in_data)
|
||||
self.assertItemsEqual(expected, out_data)
|
||||
|
||||
@mock.patch('config_tempest.profile._read_yaml_file')
|
||||
def test_read_profile_file(self, mock_read_yaml):
|
||||
profile_data = {
|
||||
'create': True,
|
||||
'overrides': {
|
||||
'auth.use_dynamic_credentials': True
|
||||
},
|
||||
'append': {
|
||||
'network-feature-enabled.api_extensions': 'ext',
|
||||
'identity-feature-enabled.api_extensions': ['ext1', 'ext2'],
|
||||
'compute-feature-enabled.api_extensions': 'ext3,ext4'
|
||||
},
|
||||
'remove': {
|
||||
'network-feature-enabled.api_extensions': 'dvr',
|
||||
'identity-feature-enabled.api_extensions': ['dvr1', 'dvr2'],
|
||||
'compute-feature-enabled.api_extensions': 'dvr3,dvr4'
|
||||
},
|
||||
'network-id': 'network_id',
|
||||
'out': './etc/tempest.conf'
|
||||
}
|
||||
mock_read_yaml.return_value = profile_data
|
||||
ret_dict = profile.read_profile_file('path')
|
||||
expected = {
|
||||
'create': True,
|
||||
'remove': [
|
||||
'network-feature-enabled.api_extensions=dvr',
|
||||
'identity-feature-enabled.api_extensions=dvr1,dvr2',
|
||||
'compute-feature-enabled.api_extensions=dvr3,dvr4'
|
||||
],
|
||||
'network-id': 'network_id',
|
||||
'overrides': [('auth', 'use_dynamic_credentials', 'True')],
|
||||
'append': [
|
||||
'network-feature-enabled.api_extensions=ext',
|
||||
'identity-feature-enabled.api_extensions=ext1,ext2',
|
||||
'compute-feature-enabled.api_extensions=ext3,ext4'
|
||||
],
|
||||
'out': './etc/tempest.conf'
|
||||
}
|
||||
for key in ['create', 'network-id', 'out']:
|
||||
self.assertEqual(expected[key], ret_dict[key])
|
||||
for key in ['remove', 'overrides', 'append']:
|
||||
self.assertListEqual(sorted(expected[key]), sorted(ret_dict[key]))
|
||||
|
Loading…
Reference in New Issue
Block a user