summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorDavid Rosales <darosale@us.ibm.com>2016-04-29 12:12:52 -0500
committerSteve Martinelli <s.martinelli@gmail.com>2016-06-22 21:55:46 -0700
commit337d013c94378a4b3f0e8f90e4f5bd745448658f (patch)
tree4dc43c30de328f0b83147e078faee22560b88bac /openstackclient/tests
parenta60f16b9385d7ee2322a25b5728363fbf8f5154b (diff)
downloadpython-openstackclient-337d013c94378a4b3f0e8f90e4f5bd745448658f.tar.gz
Use resource id when name given for identity show
Currently a user is allowed to specify either a resource ID or name when running openstack identity comands. In some cases, when a name is specified instead of an ID, the command will return as not able to find the resource when it in fact does exist. The changes here are to check the client against the token on such requests and to extract the ID of the resource specified if enough information exists between the two. We then use the ID associated with the resource to complete the user requests. Change-Id: I40713b0ded42063b786dc21247e854224b9d2fe2 Closes-Bug: #1561599
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/identity/v3/fakes.py3
-rw-r--r--openstackclient/tests/identity/v3/test_domain.py10
-rw-r--r--openstackclient/tests/identity/v3/test_project.py38
-rw-r--r--openstackclient/tests/identity/v3/test_user.py11
4 files changed, 62 insertions, 0 deletions
diff --git a/openstackclient/tests/identity/v3/fakes.py b/openstackclient/tests/identity/v3/fakes.py
index cd1b4bd7..dd918616 100644
--- a/openstackclient/tests/identity/v3/fakes.py
+++ b/openstackclient/tests/identity/v3/fakes.py
@@ -502,6 +502,9 @@ class FakeIdentityv3Client(object):
self.role_assignments.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']
+ self.auth = FakeAuth()
+ self.auth.client = mock.Mock()
+ self.auth.client.resource_class = fakes.FakeResource(None, {})
class FakeFederationManager(object):
diff --git a/openstackclient/tests/identity/v3/test_domain.py b/openstackclient/tests/identity/v3/test_domain.py
index f3777f12..e06e0681 100644
--- a/openstackclient/tests/identity/v3/test_domain.py
+++ b/openstackclient/tests/identity/v3/test_domain.py
@@ -389,6 +389,16 @@ class TestDomainShow(TestDomain):
('domain', identity_fakes.domain_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.app.client_manager.identity.tokens.get_token_data.return_value = \
+ {'token':
+ {'project':
+ {'domain':
+ {'id': 'd1',
+ 'name': 'd1'
+ }
+ }
+ }
+ }
# 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
diff --git a/openstackclient/tests/identity/v3/test_project.py b/openstackclient/tests/identity/v3/test_project.py
index 8fcada6e..93bf18af 100644
--- a/openstackclient/tests/identity/v3/test_project.py
+++ b/openstackclient/tests/identity/v3/test_project.py
@@ -749,6 +749,7 @@ class TestProjectShow(TestProject):
self.cmd = project.ShowProject(self.app, None)
def test_project_show(self):
+
arglist = [
identity_fakes.project_id,
]
@@ -757,6 +758,16 @@ class TestProjectShow(TestProject):
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.app.client_manager.identity.tokens.get_token_data.return_value = \
+ {'token':
+ {'project':
+ {'domain': {},
+ 'name': parsed_args.project,
+ 'id': parsed_args.project
+ }
+ }
+ }
+
# 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.
@@ -797,6 +808,15 @@ class TestProjectShow(TestProject):
('children', False),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.app.client_manager.identity.tokens.get_token_data.return_value = \
+ {'token':
+ {'project':
+ {'domain': {},
+ 'name': parsed_args.project,
+ 'id': parsed_args.project
+ }
+ }
+ }
columns, data = self.cmd.take_action(parsed_args)
self.projects_mock.get.assert_called_with(
@@ -845,6 +865,15 @@ class TestProjectShow(TestProject):
('children', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.app.client_manager.identity.tokens.get_token_data.return_value = \
+ {'token':
+ {'project':
+ {'domain': {},
+ 'name': parsed_args.project,
+ 'id': parsed_args.project
+ }
+ }
+ }
columns, data = self.cmd.take_action(parsed_args)
self.projects_mock.get.assert_called_with(
@@ -895,6 +924,15 @@ class TestProjectShow(TestProject):
('children', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
+ self.app.client_manager.identity.tokens.get_token_data.return_value = \
+ {'token':
+ {'project':
+ {'domain': {},
+ 'name': parsed_args.project,
+ 'id': parsed_args.project
+ }
+ }
+ }
columns, data = self.cmd.take_action(parsed_args)
self.projects_mock.get.assert_called_with(
diff --git a/openstackclient/tests/identity/v3/test_user.py b/openstackclient/tests/identity/v3/test_user.py
index 85522e57..c4fb1521 100644
--- a/openstackclient/tests/identity/v3/test_user.py
+++ b/openstackclient/tests/identity/v3/test_user.py
@@ -1094,6 +1094,17 @@ class TestUserShow(TestUser):
# Get the command object to test
self.cmd = user.ShowUser(self.app, None)
+ self.app.client_manager.identity.auth.client.get_user_id.\
+ return_value = 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa'
+ self.app.client_manager.identity.tokens.get_token_data.return_value = \
+ {'token':
+ {'user':
+ {'domain': {},
+ 'id': 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa',
+ 'name': 'bbbbbbb-aaaa-aaaa-aaaa-bbbbbbbaaaa'
+ }
+ }
+ }
def test_user_show(self):
arglist = [