summaryrefslogtreecommitdiff
path: root/openstackclient/tests
diff options
context:
space:
mode:
authorSean Perry <sean.perry@hp.com>2015-09-23 10:39:13 -0700
committerSean Perry <sean.perry@hp.com>2015-09-30 15:33:45 -0700
commitb33cdec92ab3707886c12f49e9db27981114b35d (patch)
tree32213e5d62ce78c950e60c14e44c5481f84d5467 /openstackclient/tests
parent678e69064854e3a3d3499171b0a29f30f2771840 (diff)
downloadpython-openstackclient-b33cdec92ab3707886c12f49e9db27981114b35d.tar.gz
Mark arguments for 'credential' commands as required
According to the [1], 'user_id', 'type', and 'blob' are all required arguments for 'credential set' but the code treats them as optional. Set the 'required' flag and remove logic supporting missing arguments. [1]: https://github.com/openstack/keystone-specs/blob/master/api/v3/identity-api-v3.rst#credentials-v3credentials "spec" Change-Id: I597c9616ad744385fc6dd92379feb03daec54458 Closes-Bug: #1418837
Diffstat (limited to 'openstackclient/tests')
-rw-r--r--openstackclient/tests/identity/v3/fakes.py4
-rw-r--r--openstackclient/tests/identity/v3/test_credential.py112
2 files changed, 116 insertions, 0 deletions
diff --git a/openstackclient/tests/identity/v3/fakes.py b/openstackclient/tests/identity/v3/fakes.py
index 9c4de9cc..e1793ca1 100644
--- a/openstackclient/tests/identity/v3/fakes.py
+++ b/openstackclient/tests/identity/v3/fakes.py
@@ -195,6 +195,8 @@ SERVICE_WITHOUT_NAME = {
'links': base_url + 'services/' + service_id,
}
+credential_id = 'c-123'
+
endpoint_id = 'e-123'
endpoint_url = 'http://127.0.0.1:35357'
endpoint_region = 'RegionOne'
@@ -400,6 +402,8 @@ class FakeIdentityv3Client(object):
def __init__(self, **kwargs):
self.domains = mock.Mock()
self.domains.resource_class = fakes.FakeResource(None, {})
+ self.credentials = mock.Mock()
+ self.credentials.resource_class = fakes.FakeResource(None, {})
self.endpoints = mock.Mock()
self.endpoints.resource_class = fakes.FakeResource(None, {})
self.groups = mock.Mock()
diff --git a/openstackclient/tests/identity/v3/test_credential.py b/openstackclient/tests/identity/v3/test_credential.py
new file mode 100644
index 00000000..5adcf7fa
--- /dev/null
+++ b/openstackclient/tests/identity/v3/test_credential.py
@@ -0,0 +1,112 @@
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+import json
+
+from openstackclient.identity.v3 import credential
+from openstackclient.tests.identity.v3 import fakes as identity_fakes
+from openstackclient.tests.utils import ParserException
+
+
+class TestCredential(identity_fakes.TestIdentityv3):
+ data = {
+ "access": "abc123",
+ "secret": "hidden-message",
+ "trust_id": None
+ }
+
+ def __init__(self, *args):
+ super(TestCredential, self).__init__(*args)
+
+ self.json_data = json.dumps(self.data)
+
+ def setUp(self):
+ super(TestCredential, self).setUp()
+
+ # Get a shortcut to the CredentialManager Mock
+ self.credentials_mock = self.app.client_manager.identity.credentials
+ self.credentials_mock.reset_mock()
+
+ # Get a shortcut to the UserManager Mock
+ self.users_mock = self.app.client_manager.identity.users
+ self.users_mock.reset_mock()
+
+ # Get a shortcut to the ProjectManager Mock
+ self.projects_mock = self.app.client_manager.identity.projects
+ self.projects_mock.reset_mock()
+
+
+class TestCredentialSet(TestCredential):
+ def setUp(self):
+ super(TestCredentialSet, self).setUp()
+ self.cmd = credential.SetCredential(self.app, None)
+
+ def test_credential_set_no_options(self):
+ arglist = [
+ identity_fakes.credential_id,
+ ]
+
+ self.assertRaises(ParserException,
+ self.check_parser, self.cmd, arglist, [])
+
+ def test_credential_set_missing_user(self):
+ arglist = [
+ '--type', 'ec2',
+ '--data', self.json_data,
+ identity_fakes.credential_id,
+ ]
+
+ self.assertRaises(ParserException,
+ self.check_parser, self.cmd, arglist, [])
+
+ def test_credential_set_missing_type(self):
+ arglist = [
+ '--user', identity_fakes.user_name,
+ '--data', self.json_data,
+ identity_fakes.credential_id,
+ ]
+
+ self.assertRaises(ParserException,
+ self.check_parser, self.cmd, arglist, [])
+
+ def test_credential_set_missing_data(self):
+ arglist = [
+ '--user', identity_fakes.user_name,
+ '--type', 'ec2',
+ identity_fakes.credential_id,
+ ]
+
+ self.assertRaises(ParserException,
+ self.check_parser, self.cmd, arglist, [])
+
+ def test_credential_set_valid(self):
+ arglist = [
+ '--user', identity_fakes.user_name,
+ '--type', 'ec2',
+ '--data', self.json_data,
+ identity_fakes.credential_id,
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, [])
+ self.cmd.take_action(parsed_args)
+
+ def test_credential_set_valid_with_project(self):
+ arglist = [
+ '--user', identity_fakes.user_name,
+ '--type', 'ec2',
+ '--data', self.json_data,
+ '--project', identity_fakes.project_name,
+ identity_fakes.credential_id,
+ ]
+
+ parsed_args = self.check_parser(self.cmd, arglist, [])
+ self.cmd.take_action(parsed_args)