|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +import json |
| 14 | + |
| 15 | +from openstackclient.identity.v3 import credential |
| 16 | +from openstackclient.tests.identity.v3 import fakes as identity_fakes |
| 17 | +from openstackclient.tests.utils import ParserException |
| 18 | + |
| 19 | + |
| 20 | +class TestCredential(identity_fakes.TestIdentityv3): |
| 21 | + data = { |
| 22 | + "access": "abc123", |
| 23 | + "secret": "hidden-message", |
| 24 | + "trust_id": None |
| 25 | + } |
| 26 | + |
| 27 | + def __init__(self, *args): |
| 28 | + super(TestCredential, self).__init__(*args) |
| 29 | + |
| 30 | + self.json_data = json.dumps(self.data) |
| 31 | + |
| 32 | + def setUp(self): |
| 33 | + super(TestCredential, self).setUp() |
| 34 | + |
| 35 | + # Get a shortcut to the CredentialManager Mock |
| 36 | + self.credentials_mock = self.app.client_manager.identity.credentials |
| 37 | + self.credentials_mock.reset_mock() |
| 38 | + |
| 39 | + # Get a shortcut to the UserManager Mock |
| 40 | + self.users_mock = self.app.client_manager.identity.users |
| 41 | + self.users_mock.reset_mock() |
| 42 | + |
| 43 | + # Get a shortcut to the ProjectManager Mock |
| 44 | + self.projects_mock = self.app.client_manager.identity.projects |
| 45 | + self.projects_mock.reset_mock() |
| 46 | + |
| 47 | + |
| 48 | +class TestCredentialSet(TestCredential): |
| 49 | + def setUp(self): |
| 50 | + super(TestCredentialSet, self).setUp() |
| 51 | + self.cmd = credential.SetCredential(self.app, None) |
| 52 | + |
| 53 | + def test_credential_set_no_options(self): |
| 54 | + arglist = [ |
| 55 | + identity_fakes.credential_id, |
| 56 | + ] |
| 57 | + |
| 58 | + self.assertRaises(ParserException, |
| 59 | + self.check_parser, self.cmd, arglist, []) |
| 60 | + |
| 61 | + def test_credential_set_missing_user(self): |
| 62 | + arglist = [ |
| 63 | + '--type', 'ec2', |
| 64 | + '--data', self.json_data, |
| 65 | + identity_fakes.credential_id, |
| 66 | + ] |
| 67 | + |
| 68 | + self.assertRaises(ParserException, |
| 69 | + self.check_parser, self.cmd, arglist, []) |
| 70 | + |
| 71 | + def test_credential_set_missing_type(self): |
| 72 | + arglist = [ |
| 73 | + '--user', identity_fakes.user_name, |
| 74 | + '--data', self.json_data, |
| 75 | + identity_fakes.credential_id, |
| 76 | + ] |
| 77 | + |
| 78 | + self.assertRaises(ParserException, |
| 79 | + self.check_parser, self.cmd, arglist, []) |
| 80 | + |
| 81 | + def test_credential_set_missing_data(self): |
| 82 | + arglist = [ |
| 83 | + '--user', identity_fakes.user_name, |
| 84 | + '--type', 'ec2', |
| 85 | + identity_fakes.credential_id, |
| 86 | + ] |
| 87 | + |
| 88 | + self.assertRaises(ParserException, |
| 89 | + self.check_parser, self.cmd, arglist, []) |
| 90 | + |
| 91 | + def test_credential_set_valid(self): |
| 92 | + arglist = [ |
| 93 | + '--user', identity_fakes.user_name, |
| 94 | + '--type', 'ec2', |
| 95 | + '--data', self.json_data, |
| 96 | + identity_fakes.credential_id, |
| 97 | + ] |
| 98 | + |
| 99 | + parsed_args = self.check_parser(self.cmd, arglist, []) |
| 100 | + self.cmd.take_action(parsed_args) |
| 101 | + |
| 102 | + def test_credential_set_valid_with_project(self): |
| 103 | + arglist = [ |
| 104 | + '--user', identity_fakes.user_name, |
| 105 | + '--type', 'ec2', |
| 106 | + '--data', self.json_data, |
| 107 | + '--project', identity_fakes.project_name, |
| 108 | + identity_fakes.credential_id, |
| 109 | + ] |
| 110 | + |
| 111 | + parsed_args = self.check_parser(self.cmd, arglist, []) |
| 112 | + self.cmd.take_action(parsed_args) |
0 commit comments