summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authoryanpuqing <yanpq@awcloud.com>2019-05-20 06:47:44 +0000
committerLance Bragstad <lbragstad@gmail.com>2020-05-29 07:53:13 -0500
commit533af9f1b2de40d98f69e83cdf89ecf254cf3879 (patch)
tree7f051740fee1f89671aceb2a85a6b266194d10f7 /openstackclient
parentf6ee42cd32833bf7484cbf18eab9ed110a5e9782 (diff)
downloadpython-openstackclient-533af9f1b2de40d98f69e83cdf89ecf254cf3879.tar.gz
Client should parse string to boolean for value 'is_domain'
When we use "--property" parameter, client get lists these the value is string type, but the type of the value 'is_domain' should be boolean, so we should judge it and parse it. The patch parse string to boolean for value 'is_domain'. Co-Authored-By: Lance Bragstad <lbragstad@gmail.com> Change-Id: I37c9eb854524bde3a1530bfe2e3a03810fb1a676 Task: 30039 Story: 2005246
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/identity/v3/project.py8
-rw-r--r--openstackclient/tests/unit/identity/v3/test_project.py120
2 files changed, 128 insertions, 0 deletions
diff --git a/openstackclient/identity/v3/project.py b/openstackclient/identity/v3/project.py
index e32da165..5e8ce829 100644
--- a/openstackclient/identity/v3/project.py
+++ b/openstackclient/identity/v3/project.py
@@ -106,6 +106,14 @@ class CreateProject(command.ShowOne):
kwargs = {}
if parsed_args.property:
kwargs = parsed_args.property.copy()
+ if 'is_domain' in kwargs.keys():
+ if kwargs['is_domain'].lower() == "true":
+ kwargs['is_domain'] = True
+ elif kwargs['is_domain'].lower() == "false":
+ kwargs['is_domain'] = False
+ elif kwargs['is_domain'].lower() == "none":
+ kwargs['is_domain'] = None
+
kwargs['tags'] = list(set(parsed_args.tags))
try:
diff --git a/openstackclient/tests/unit/identity/v3/test_project.py b/openstackclient/tests/unit/identity/v3/test_project.py
index 8852aa8e..dfd0805b 100644
--- a/openstackclient/tests/unit/identity/v3/test_project.py
+++ b/openstackclient/tests/unit/identity/v3/test_project.py
@@ -357,6 +357,126 @@ class TestProjectCreate(TestProject):
self.assertEqual(self.columns, columns)
self.assertEqual(self.datalist, data)
+ def test_project_create_is_domain_false_property(self):
+ arglist = [
+ '--property', 'is_domain=false',
+ self.project.name,
+ ]
+ verifylist = [
+ ('parent', None),
+ ('enable', False),
+ ('disable', False),
+ ('name', self.project.name),
+ ('tags', []),
+ ('property', {'is_domain': 'false'}),
+ ('name', self.project.name),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'name': self.project.name,
+ 'domain': None,
+ 'description': None,
+ 'enabled': True,
+ 'parent': None,
+ 'is_domain': False,
+ 'tags': [],
+ 'options': {},
+ }
+ self.projects_mock.create.assert_called_with(
+ **kwargs
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.datalist, data)
+
+ def test_project_create_is_domain_true_property(self):
+ arglist = [
+ '--property', 'is_domain=true',
+ self.project.name,
+ ]
+ verifylist = [
+ ('parent', None),
+ ('enable', False),
+ ('disable', False),
+ ('name', self.project.name),
+ ('tags', []),
+ ('property', {'is_domain': 'true'}),
+ ('name', self.project.name),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'name': self.project.name,
+ 'domain': None,
+ 'description': None,
+ 'enabled': True,
+ 'parent': None,
+ 'is_domain': True,
+ 'tags': [],
+ 'options': {},
+ }
+ self.projects_mock.create.assert_called_with(
+ **kwargs
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.datalist, data)
+
+ def test_project_create_is_domain_none_property(self):
+ arglist = [
+ '--property', 'is_domain=none',
+ self.project.name,
+ ]
+ verifylist = [
+ ('parent', None),
+ ('enable', False),
+ ('disable', False),
+ ('name', self.project.name),
+ ('tags', []),
+ ('property', {'is_domain': 'none'}),
+ ('name', self.project.name),
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+
+ # In base command class ShowOne in cliff, abstract method take_action()
+ # returns a two-part tuple with a tuple of column names and a tuple of
+ # data to be shown.
+ columns, data = self.cmd.take_action(parsed_args)
+
+ # Set expected values
+ kwargs = {
+ 'name': self.project.name,
+ 'domain': None,
+ 'description': None,
+ 'enabled': True,
+ 'parent': None,
+ 'is_domain': None,
+ 'tags': [],
+ 'options': {},
+ }
+ self.projects_mock.create.assert_called_with(
+ **kwargs
+ )
+
+ self.assertEqual(self.columns, columns)
+ self.assertEqual(self.datalist, data)
+
def test_project_create_parent(self):
self.parent = identity_fakes.FakeProject.create_one_project()
self.project = identity_fakes.FakeProject.create_one_project(