|
| 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 copy |
| 14 | + |
| 15 | +from openstackclient.common import exceptions |
| 16 | +from openstackclient.identity.v3 import unscoped_saml |
| 17 | +from openstackclient.tests import fakes |
| 18 | +from openstackclient.tests.identity.v3 import fakes as identity_fakes |
| 19 | + |
| 20 | + |
| 21 | +class TestUnscopedSAML(identity_fakes.TestFederatedIdentity): |
| 22 | + |
| 23 | + def setUp(self): |
| 24 | + super(TestUnscopedSAML, self).setUp() |
| 25 | + |
| 26 | + federation_lib = self.app.client_manager.identity.federation |
| 27 | + self.projects_mock = federation_lib.projects |
| 28 | + self.projects_mock.reset_mock() |
| 29 | + self.domains_mock = federation_lib.domains |
| 30 | + self.domains_mock.reset_mock() |
| 31 | + |
| 32 | + |
| 33 | +class TestProjectList(TestUnscopedSAML): |
| 34 | + |
| 35 | + def setUp(self): |
| 36 | + super(TestProjectList, self).setUp() |
| 37 | + |
| 38 | + self.projects_mock.list.return_value = [ |
| 39 | + fakes.FakeResource( |
| 40 | + None, |
| 41 | + copy.deepcopy(identity_fakes.PROJECT), |
| 42 | + loaded=True, |
| 43 | + ), |
| 44 | + ] |
| 45 | + |
| 46 | + # Get the command object to test |
| 47 | + self.cmd = unscoped_saml.ListAccessibleProjects(self.app, None) |
| 48 | + |
| 49 | + def test_accessible_projects_list(self): |
| 50 | + self.app.client_manager.auth_plugin_name = 'v3unscopedsaml' |
| 51 | + arglist = [] |
| 52 | + verifylist = [] |
| 53 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 54 | + |
| 55 | + # DisplayCommandBase.take_action() returns two tuples |
| 56 | + columns, data = self.cmd.take_action(parsed_args) |
| 57 | + |
| 58 | + self.projects_mock.list.assert_called_with() |
| 59 | + |
| 60 | + collist = ('ID', 'Domain ID', 'Enabled', 'Name') |
| 61 | + self.assertEqual(columns, collist) |
| 62 | + datalist = (( |
| 63 | + identity_fakes.project_id, |
| 64 | + identity_fakes.domain_id, |
| 65 | + True, |
| 66 | + identity_fakes.project_name, |
| 67 | + ), ) |
| 68 | + self.assertEqual(tuple(data), datalist) |
| 69 | + |
| 70 | + def test_accessible_projects_list_wrong_auth(self): |
| 71 | + auth = identity_fakes.FakeAuth("wrong auth") |
| 72 | + self.app.client_manager.identity.session.auth = auth |
| 73 | + arglist = [] |
| 74 | + verifylist = [] |
| 75 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 76 | + |
| 77 | + self.assertRaises(exceptions.CommandError, |
| 78 | + self.cmd.take_action, |
| 79 | + parsed_args) |
| 80 | + |
| 81 | + |
| 82 | +class TestDomainList(TestUnscopedSAML): |
| 83 | + |
| 84 | + def setUp(self): |
| 85 | + super(TestDomainList, self).setUp() |
| 86 | + |
| 87 | + self.domains_mock.list.return_value = [ |
| 88 | + fakes.FakeResource( |
| 89 | + None, |
| 90 | + copy.deepcopy(identity_fakes.DOMAIN), |
| 91 | + loaded=True, |
| 92 | + ), |
| 93 | + ] |
| 94 | + |
| 95 | + # Get the command object to test |
| 96 | + self.cmd = unscoped_saml.ListAccessibleDomains(self.app, None) |
| 97 | + |
| 98 | + def test_accessible_domains_list(self): |
| 99 | + self.app.client_manager.auth_plugin_name = 'v3unscopedsaml' |
| 100 | + arglist = [] |
| 101 | + verifylist = [] |
| 102 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 103 | + |
| 104 | + # DisplayCommandBase.take_action() returns two tuples |
| 105 | + columns, data = self.cmd.take_action(parsed_args) |
| 106 | + |
| 107 | + self.domains_mock.list.assert_called_with() |
| 108 | + |
| 109 | + collist = ('ID', 'Enabled', 'Name', 'Description') |
| 110 | + self.assertEqual(columns, collist) |
| 111 | + datalist = (( |
| 112 | + identity_fakes.domain_id, |
| 113 | + True, |
| 114 | + identity_fakes.domain_name, |
| 115 | + identity_fakes.domain_description, |
| 116 | + ), ) |
| 117 | + self.assertEqual(tuple(data), datalist) |
| 118 | + |
| 119 | + def test_accessible_domains_list_wrong_auth(self): |
| 120 | + auth = identity_fakes.FakeAuth("wrong auth") |
| 121 | + self.app.client_manager.identity.session.auth = auth |
| 122 | + arglist = [] |
| 123 | + verifylist = [] |
| 124 | + parsed_args = self.check_parser(self.cmd, arglist, verifylist) |
| 125 | + |
| 126 | + self.assertRaises(exceptions.CommandError, |
| 127 | + self.cmd.take_action, |
| 128 | + parsed_args) |
0 commit comments