Merge "Add tests for identity endpoints"

This commit is contained in:
Jenkins 2014-06-10 02:27:55 +00:00 committed by Gerrit Code Review
commit 7f6a901d01
2 changed files with 288 additions and 0 deletions

View File

@ -80,6 +80,26 @@ TOKEN = {
'user_id': user_id,
}
endpoint_name = service_name
endpoint_adminurl = 'https://admin.example.com/v2/UUID'
endpoint_region = 'RegionOne'
endpoint_internalurl = 'https://internal.example.com/v2/UUID'
endpoint_type = service_type
endpoint_id = '11b41ee1b00841128b7333d4bf1a6140'
endpoint_publicurl = 'https://public.example.com/v2/UUID'
endpoint_service_id = service_id
ENDPOINT = {
'service_name': endpoint_name,
'adminurl': endpoint_adminurl,
'region': endpoint_region,
'internalurl': endpoint_internalurl,
'service_type': endpoint_type,
'id': endpoint_id,
'publicurl': endpoint_publicurl,
'service_id': endpoint_service_id,
}
class FakeIdentityv2Client(object):
def __init__(self, **kwargs):
@ -94,6 +114,8 @@ class FakeIdentityv2Client(object):
self.users.resource_class = fakes.FakeResource(None, {})
self.ec2 = mock.Mock()
self.ec2.resource_class = fakes.FakeResource(None, {})
self.endpoints = mock.Mock()
self.endpoints.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']

View File

@ -0,0 +1,266 @@
# 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 copy
from openstackclient.identity.v2_0 import endpoint
from openstackclient.tests import fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
class TestEndpoint(identity_fakes.TestIdentityv2):
def setUp(self):
super(TestEndpoint, self).setUp()
# Get a shortcut to the EndpointManager Mock
self.endpoints_mock = self.app.client_manager.identity.endpoints
self.endpoints_mock.reset_mock()
# Get a shortcut to the ServiceManager Mock
self.services_mock = self.app.client_manager.identity.services
self.services_mock.reset_mock()
class TestEndpointCreate(TestEndpoint):
def setUp(self):
super(TestEndpointCreate, self).setUp()
self.endpoints_mock.create.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
)
self.services_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
# Get the command object to test
self.cmd = endpoint.CreateEndpoint(self.app, None)
def test_endpoint_create(self):
arglist = [
'--publicurl', identity_fakes.endpoint_publicurl,
'--internalurl', identity_fakes.endpoint_internalurl,
'--adminurl', identity_fakes.endpoint_adminurl,
'--region', identity_fakes.endpoint_region,
identity_fakes.endpoint_name,
]
verifylist = [
('adminurl', identity_fakes.endpoint_adminurl),
('internalurl', identity_fakes.endpoint_internalurl),
('publicurl', identity_fakes.endpoint_publicurl),
('region', identity_fakes.endpoint_region),
('service', identity_fakes.service_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# EndpointManager.create(region, service_id, publicurl, adminurl,
# internalurl)
self.endpoints_mock.create.assert_called_with(
identity_fakes.endpoint_region,
identity_fakes.service_id,
identity_fakes.endpoint_publicurl,
identity_fakes.endpoint_adminurl,
identity_fakes.endpoint_internalurl,
)
collist = ('adminurl', 'id', 'internalurl', 'publicurl',
'region', 'service_id', 'service_name', 'service_type')
self.assertEqual(columns, collist)
datalist = (
identity_fakes.endpoint_adminurl,
identity_fakes.endpoint_id,
identity_fakes.endpoint_internalurl,
identity_fakes.endpoint_publicurl,
identity_fakes.endpoint_region,
identity_fakes.service_id,
identity_fakes.service_name,
identity_fakes.service_type,
)
self.assertEqual(data, datalist)
class TestEndpointDelete(TestEndpoint):
def setUp(self):
super(TestEndpointDelete, self).setUp()
self.endpoints_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
)
self.services_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
self.endpoints_mock.delete.return_value = None
# Get the command object to test
self.cmd = endpoint.DeleteEndpoint(self.app, None)
def test_endpoint_delete_no_options(self):
arglist = [
identity_fakes.endpoint_id,
]
verifylist = [
('endpoint', identity_fakes.endpoint_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args)
self.endpoints_mock.delete.assert_called_with(
identity_fakes.endpoint_id,
)
class TestEndpointList(TestEndpoint):
def setUp(self):
super(TestEndpointList, self).setUp()
self.endpoints_mock.list.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
),
]
self.services_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
# Get the command object to test
self.cmd = endpoint.ListEndpoint(self.app, None)
def test_endpoint_list_no_options(self):
arglist = []
verifylist = []
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.endpoints_mock.list.assert_called_with()
collist = ('ID', 'Region', 'Service Name', 'Service Type')
self.assertEqual(columns, collist)
datalist = ((
identity_fakes.endpoint_id,
identity_fakes.endpoint_region,
identity_fakes.service_name,
identity_fakes.service_type,
), )
self.assertEqual(tuple(data), datalist)
def test_endpoint_list_long(self):
arglist = [
'--long',
]
verifylist = [
('long', True),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
self.endpoints_mock.list.assert_called_with()
collist = ('ID', 'Region', 'Service Name', 'Service Type',
'PublicURL', 'AdminURL', 'InternalURL')
self.assertEqual(columns, collist)
datalist = ((
identity_fakes.endpoint_id,
identity_fakes.endpoint_region,
identity_fakes.service_name,
identity_fakes.service_type,
identity_fakes.endpoint_publicurl,
identity_fakes.endpoint_adminurl,
identity_fakes.endpoint_internalurl,
), )
self.assertEqual(tuple(data), datalist)
class TestEndpointShow(TestEndpoint):
def setUp(self):
super(TestEndpointShow, self).setUp()
self.endpoints_mock.list.return_value = [
fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.ENDPOINT),
loaded=True,
),
]
self.services_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.SERVICE),
loaded=True,
)
# Get the command object to test
self.cmd = endpoint.ShowEndpoint(self.app, None)
def test_endpoint_show(self):
arglist = [
identity_fakes.endpoint_name,
]
verifylist = [
('endpoint_or_service', identity_fakes.endpoint_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# EndpointManager.list()
self.endpoints_mock.list.assert_called_with()
# ServiceManager.get(name)
self.services_mock.get.assert_called_with(
identity_fakes.service_name,
)
collist = ('adminurl', 'id', 'internalurl', 'publicurl',
'region', 'service_id', 'service_name', 'service_type')
self.assertEqual(columns, collist)
datalist = (
identity_fakes.endpoint_adminurl,
identity_fakes.endpoint_id,
identity_fakes.endpoint_internalurl,
identity_fakes.endpoint_publicurl,
identity_fakes.endpoint_region,
identity_fakes.service_id,
identity_fakes.service_name,
identity_fakes.service_type,
)
self.assertEqual(data, datalist)