openstacksdk/shade/tests/unit/test_domain_params.py
Monty Taylor 8b47d15fd5
Use new keystoneauth version discovery
We can remove a ton of our logic. We still need SOME because we have a
different fallback strategy that isn't appropriate for keystoneauth
generally.

There are a couple of tests removed, since they were testing shade code
that was removed. Also it's worth noting that there are tests in
test_domain_params and test_image that are mocking the client rather
than mocking the requests and we should fix those.

Co-authored-by: Samuel de Medeiros Queiroz <samueldmq@gmail.com>
Change-Id: I78019717cdee79cab43b0d11e737327aa281fd03
2017-09-01 10:10:29 -05:00

74 lines
3.0 KiB
Python

# 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 mock
import munch
import shade
from shade import exc
from shade.tests.unit import base
class TestDomainParams(base.TestCase):
@mock.patch.object(shade.OpenStackCloud, '_is_client_version')
@mock.patch.object(shade.OpenStackCloud, 'get_project')
def test_identity_params_v3(self, mock_get_project,
mock_is_client_version):
mock_get_project.return_value = munch.Munch(id=1234)
mock_is_client_version.return_value = True
ret = self.cloud._get_identity_params(domain_id='5678', project='bar')
self.assertIn('default_project_id', ret)
self.assertEqual(ret['default_project_id'], 1234)
self.assertIn('domain_id', ret)
self.assertEqual(ret['domain_id'], '5678')
@mock.patch.object(shade.OpenStackCloud, '_is_client_version')
@mock.patch.object(shade.OpenStackCloud, 'get_project')
def test_identity_params_v3_no_domain(
self, mock_get_project, mock_is_client_version):
mock_get_project.return_value = munch.Munch(id=1234)
mock_is_client_version.return_value = True
self.assertRaises(
exc.OpenStackCloudException,
self.cloud._get_identity_params,
domain_id=None, project='bar')
@mock.patch.object(shade.OpenStackCloud, '_is_client_version')
@mock.patch.object(shade.OpenStackCloud, 'get_project')
def test_identity_params_v2(self, mock_get_project,
mock_is_client_version):
mock_get_project.return_value = munch.Munch(id=1234)
mock_is_client_version.return_value = False
ret = self.cloud._get_identity_params(domain_id='foo', project='bar')
self.assertIn('tenant_id', ret)
self.assertEqual(ret['tenant_id'], 1234)
self.assertNotIn('domain', ret)
@mock.patch.object(shade.OpenStackCloud, '_is_client_version')
@mock.patch.object(shade.OpenStackCloud, 'get_project')
def test_identity_params_v2_no_domain(self, mock_get_project,
mock_is_client_version):
mock_get_project.return_value = munch.Munch(id=1234)
mock_is_client_version.return_value = False
ret = self.cloud._get_identity_params(domain_id=None, project='bar')
api_calls = [mock.call('identity', 3), mock.call('identity', 3)]
mock_is_client_version.assert_has_calls(api_calls)
self.assertIn('tenant_id', ret)
self.assertEqual(ret['tenant_id'], 1234)
self.assertNotIn('domain', ret)