Source code for openstack_dashboard.test.api_tests.keystone_tests

# vim: tabstop=4 shiftwidth=4 softtabstop=4

# Copyright 2012 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Copyright 2012 Nebula, Inc.
#
#    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.

from __future__ import absolute_import

from keystoneclient.v2_0 import client as keystone_client

from openstack_dashboard import api
from openstack_dashboard.test import helpers as test


[docs]class FakeConnection(object): pass
[docs]class ClientConnectionTests(test.TestCase):
[docs] def setUp(self): super(ClientConnectionTests, self).setUp() self.mox.StubOutWithMock(keystone_client, "Client") self.internal_url = api.base.url_for(self.request, 'identity', endpoint_type='internalURL') self.admin_url = api.base.url_for(self.request, 'identity', endpoint_type='adminURL') self.conn = FakeConnection()
[docs]class RoleAPITests(test.APITestCase):
[docs] def setUp(self): super(RoleAPITests, self).setUp() self.role = self.roles.member self.roles = self.roles.list()
[docs] def test_remove_tenant_user(self): """Tests api.keystone.remove_tenant_user Verifies that remove_tenant_user is called with the right arguments after iterating the user's roles. There are no assertions in this test because the checking is handled by mox in the VerifyAll() call in tearDown(). """ keystoneclient = self.stub_keystoneclient() tenant = self.tenants.first() keystoneclient.roles = self.mox.CreateMockAnything() keystoneclient.roles.roles_for_user(self.user.id, tenant.id).AndReturn(self.roles) for role in self.roles: keystoneclient.roles.revoke(role.id, domain=None, group=None, project=tenant.id, user=self.user.id) self.mox.ReplayAll() api.keystone.remove_tenant_user(self.request, tenant.id, self.user.id)
[docs] def test_get_default_role(self): keystoneclient = self.stub_keystoneclient() keystoneclient.roles = self.mox.CreateMockAnything() keystoneclient.roles.list().AndReturn(self.roles) self.mox.ReplayAll() role = api.keystone.get_default_role(self.request) self.assertEqual(role, self.role) # Verify that a second call doesn't hit the API again, # (it would show up in mox as an unexpected method call) role = api.keystone.get_default_role(self.request)
[docs]class ServiceAPITests(test.APITestCase):
[docs] def test_service_wrapper(self): catalog = self.service_catalog identity_data = api.base.get_service_from_catalog(catalog, "identity") identity_data['id'] = 1 region = identity_data["endpoints"][0]["region"] service = api.keystone.Service(identity_data, region) self.assertEqual(unicode(service), u"identity (native backend)") self.assertEqual(service.region, identity_data["endpoints"][0]["region"]) self.assertEqual(service.url, "http://int.keystone.example.com:5000/v2.0") self.assertEqual(service.public_url, "http://public.keystone.example.com:5000/v2.0") self.assertEqual(service.host, "int.keystone.example.com")
[docs] def test_service_wrapper_service_in_region(self): catalog = self.service_catalog compute_data = api.base.get_service_from_catalog(catalog, "compute") compute_data['id'] = 1 region = compute_data["endpoints"][1]["region"] service = api.keystone.Service(compute_data, region) self.assertEqual(unicode(service), u"compute") self.assertEqual(service.region, compute_data["endpoints"][1]["region"]) self.assertEqual(service.url, "http://int.nova2.example.com:8774/v2") self.assertEqual(service.public_url, "http://public.nova2.example.com:8774/v2") self.assertEqual(service.host, "int.nova2.example.com")