Merge "md-property-create: add a mandatory "--type" option"

This commit is contained in:
Zuul 2023-06-28 16:41:03 +00:00 committed by Gerrit Code Review
commit f53d6714fd
2 changed files with 9 additions and 3 deletions

View File

@ -2940,13 +2940,15 @@ class ShellV2Test(testtools.TestCase):
args = self._make_args({'namespace': 'MyNamespace',
'name': "MyProperty",
'title': "Title",
'type': 'boolean',
'schema': '{}'})
with mock.patch.object(self.gc.metadefs_property,
'create') as mocked_create:
expect_property = {
'namespace': 'MyNamespace',
'name': 'MyProperty',
'title': 'Title'
'title': 'Title',
'type': 'boolean',
}
mocked_create.return_value = expect_property
@ -2955,13 +2957,15 @@ class ShellV2Test(testtools.TestCase):
mocked_create.assert_called_once_with('MyNamespace',
name='MyProperty',
title='Title')
title='Title',
type='boolean')
utils.print_dict.assert_called_once_with(expect_property)
def test_do_md_property_create_invalid_schema(self):
args = self._make_args({'namespace': 'MyNamespace',
'name': "MyProperty",
'title': "Title",
'type': "boolean",
'schema': 'Invalid'})
self.assertRaises(SystemExit, test_shell.do_md_property_create,
self.gc, args)

View File

@ -1218,6 +1218,8 @@ def do_md_namespace_resource_type_list(gc, args):
help=_('Property name displayed to the user.'))
@utils.arg('--schema', metavar='<SCHEMA>', required=True,
help=_('Valid JSON schema of a property.'))
@utils.arg('--type', metavar='<TYPE>', required=True,
help=_('Type of the property'))
def do_md_property_create(gc, args):
"""Create a new metadata definitions property inside a namespace."""
try:
@ -1225,7 +1227,7 @@ def do_md_property_create(gc, args):
except ValueError:
utils.exit('Schema is not a valid JSON object.')
else:
fields = {'name': args.name, 'title': args.title}
fields = {'name': args.name, 'title': args.title, 'type': args.type}
fields.update(schema)
new_property = gc.metadefs_property.create(args.namespace, **fields)
utils.print_dict(new_property)