Skip to content

Commit 533af9f

Browse files
ycx516lbragstad
authored andcommitted
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
1 parent f6ee42c commit 533af9f

File tree

3 files changed

+133
-0
lines changed

3 files changed

+133
-0
lines changed

openstackclient/identity/v3/project.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ def take_action(self, parsed_args):
106106
kwargs = {}
107107
if parsed_args.property:
108108
kwargs = parsed_args.property.copy()
109+
if 'is_domain' in kwargs.keys():
110+
if kwargs['is_domain'].lower() == "true":
111+
kwargs['is_domain'] = True
112+
elif kwargs['is_domain'].lower() == "false":
113+
kwargs['is_domain'] = False
114+
elif kwargs['is_domain'].lower() == "none":
115+
kwargs['is_domain'] = None
116+
109117
kwargs['tags'] = list(set(parsed_args.tags))
110118

111119
try:

openstackclient/tests/unit/identity/v3/test_project.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,126 @@ def test_project_create_property(self):
357357
self.assertEqual(self.columns, columns)
358358
self.assertEqual(self.datalist, data)
359359

360+
def test_project_create_is_domain_false_property(self):
361+
arglist = [
362+
'--property', 'is_domain=false',
363+
self.project.name,
364+
]
365+
verifylist = [
366+
('parent', None),
367+
('enable', False),
368+
('disable', False),
369+
('name', self.project.name),
370+
('tags', []),
371+
('property', {'is_domain': 'false'}),
372+
('name', self.project.name),
373+
]
374+
375+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
376+
377+
# In base command class ShowOne in cliff, abstract method take_action()
378+
# returns a two-part tuple with a tuple of column names and a tuple of
379+
# data to be shown.
380+
columns, data = self.cmd.take_action(parsed_args)
381+
382+
# Set expected values
383+
kwargs = {
384+
'name': self.project.name,
385+
'domain': None,
386+
'description': None,
387+
'enabled': True,
388+
'parent': None,
389+
'is_domain': False,
390+
'tags': [],
391+
'options': {},
392+
}
393+
self.projects_mock.create.assert_called_with(
394+
**kwargs
395+
)
396+
397+
self.assertEqual(self.columns, columns)
398+
self.assertEqual(self.datalist, data)
399+
400+
def test_project_create_is_domain_true_property(self):
401+
arglist = [
402+
'--property', 'is_domain=true',
403+
self.project.name,
404+
]
405+
verifylist = [
406+
('parent', None),
407+
('enable', False),
408+
('disable', False),
409+
('name', self.project.name),
410+
('tags', []),
411+
('property', {'is_domain': 'true'}),
412+
('name', self.project.name),
413+
]
414+
415+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
416+
417+
# In base command class ShowOne in cliff, abstract method take_action()
418+
# returns a two-part tuple with a tuple of column names and a tuple of
419+
# data to be shown.
420+
columns, data = self.cmd.take_action(parsed_args)
421+
422+
# Set expected values
423+
kwargs = {
424+
'name': self.project.name,
425+
'domain': None,
426+
'description': None,
427+
'enabled': True,
428+
'parent': None,
429+
'is_domain': True,
430+
'tags': [],
431+
'options': {},
432+
}
433+
self.projects_mock.create.assert_called_with(
434+
**kwargs
435+
)
436+
437+
self.assertEqual(self.columns, columns)
438+
self.assertEqual(self.datalist, data)
439+
440+
def test_project_create_is_domain_none_property(self):
441+
arglist = [
442+
'--property', 'is_domain=none',
443+
self.project.name,
444+
]
445+
verifylist = [
446+
('parent', None),
447+
('enable', False),
448+
('disable', False),
449+
('name', self.project.name),
450+
('tags', []),
451+
('property', {'is_domain': 'none'}),
452+
('name', self.project.name),
453+
]
454+
455+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
456+
457+
# In base command class ShowOne in cliff, abstract method take_action()
458+
# returns a two-part tuple with a tuple of column names and a tuple of
459+
# data to be shown.
460+
columns, data = self.cmd.take_action(parsed_args)
461+
462+
# Set expected values
463+
kwargs = {
464+
'name': self.project.name,
465+
'domain': None,
466+
'description': None,
467+
'enabled': True,
468+
'parent': None,
469+
'is_domain': None,
470+
'tags': [],
471+
'options': {},
472+
}
473+
self.projects_mock.create.assert_called_with(
474+
**kwargs
475+
)
476+
477+
self.assertEqual(self.columns, columns)
478+
self.assertEqual(self.datalist, data)
479+
360480
def test_project_create_parent(self):
361481
self.parent = identity_fakes.FakeProject.create_one_project()
362482
self.project = identity_fakes.FakeProject.create_one_project(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
[Story `2005246 <https://storyboard.openstack.org/#!/story/2005246>`_]
5+
The `is_domain` property safely handles type checking.

0 commit comments

Comments
 (0)