Complete basic test infrastructure

This finally gets all of the API tests into a common framework regarding
test classes and so forth.

Change-Id: If675347129c50dcba0bfc5b6c58f5a2ca57ff46c
This commit is contained in:
Dean Troyer 2013-11-15 17:40:09 -06:00
parent c946192e37
commit 6460f1eb35
29 changed files with 653 additions and 439 deletions

View File

@ -213,7 +213,7 @@ class DeleteImage(command.Command):
image_client.images, image_client.images,
parsed_args.image, parsed_args.image,
) )
image_client.images.delete(image) image_client.images.delete(image.id)
class ListImage(lister.Lister): class ListImage(lister.Lister):

View File

@ -1,50 +0,0 @@
# Copyright 2013 OpenStack, LLC.
#
# 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
from openstackclient.common import clientmanager
from openstackclient.compute import client as compute_client
from openstackclient.tests import utils
AUTH_TOKEN = "foobar"
AUTH_URL = "http://0.0.0.0"
class FakeClient(object):
def __init__(self, endpoint=None, **kwargs):
self.client = mock.MagicMock()
self.client.auth_url = AUTH_URL
class TestCompute(utils.TestCase):
def setUp(self):
super(TestCompute, self).setUp()
api_version = {"compute": "2"}
compute_client.API_VERSIONS = {
"2": "openstackclient.tests.compute.test_compute.FakeClient"
}
self.cm = clientmanager.ClientManager(token=AUTH_TOKEN,
url=AUTH_URL,
auth_url=AUTH_URL,
api_version=api_version)
def test_make_client(self):
self.assertEqual(self.cm.compute.client.auth_token, AUTH_TOKEN)
self.assertEqual(self.cm.compute.client.auth_url, AUTH_URL)

View File

@ -1,4 +1,4 @@
# Copyright 2013 Nebula Inc. # Copyright 2013 OpenStack Foundation
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
@ -12,20 +12,3 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
from openstackclient.tests.identity.v3 import fakes
from openstackclient.tests import utils
AUTH_TOKEN = "foobar"
AUTH_URL = "http://0.0.0.0"
class TestIdentityv3(utils.TestCommand):
def setUp(self):
super(TestIdentityv3, self).setUp()
self.app.client_manager.identity = fakes.FakeIdentityv3Client(
endpoint=AUTH_URL,
token=AUTH_TOKEN,
)

View File

@ -0,0 +1,55 @@
# Copyright 2013 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.
#
import mock
from openstackclient.tests import fakes
from openstackclient.tests import utils
image_id = 'im1'
IMAGE = {
'id': image_id,
}
server_id = 'serv1'
server_name = 'waiter'
SERVER = {
'id': server_id,
'name': server_name,
}
class FakeComputev2Client(object):
def __init__(self, **kwargs):
self.images = mock.Mock()
self.images.resource_class = fakes.FakeResource(None, {})
self.servers = mock.Mock()
self.servers.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']
class TestComputev2(utils.TestCommand):
def setUp(self):
super(TestComputev2, self).setUp()
self.app.client_manager.compute = FakeComputev2Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)

View File

@ -0,0 +1,63 @@
# Copyright 2013 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.
#
import copy
from openstackclient.compute.v2 import server
from openstackclient.tests.compute.v2 import fakes as compute_fakes
from openstackclient.tests import fakes
class TestServer(compute_fakes.TestComputev2):
def setUp(self):
super(TestServer, self).setUp()
# Get a shortcut to the ServerManager Mock
self.servers_mock = self.app.client_manager.compute.servers
self.servers_mock.reset_mock()
class TestServerDelete(TestServer):
def setUp(self):
super(TestServerDelete, self).setUp()
# This is the return value for utils.find_resource()
self.servers_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(compute_fakes.SERVER),
loaded=True,
)
self.servers_mock.delete.return_value = None
# Get the command object to test
self.cmd = server.DeleteServer(self.app, None)
def test_server_delete_no_options(self):
arglist = [
compute_fakes.server_id,
]
verifylist = [
('server', compute_fakes.server_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args)
self.servers_mock.delete.assert_called_with(
compute_fakes.server_id,
)

View File

@ -16,6 +16,10 @@
import sys import sys
AUTH_TOKEN = "foobar"
AUTH_URL = "http://0.0.0.0"
class FakeStdout: class FakeStdout:
def __init__(self): def __init__(self):
self.content = [] self.content = []

View File

@ -16,6 +16,8 @@
import mock import mock
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests import utils
project_id = '8-9-64' project_id = '8-9-64'
project_name = 'beatles' project_name = 'beatles'
@ -83,3 +85,13 @@ class FakeIdentityv2Client(object):
self.ec2.resource_class = fakes.FakeResource(None, {}) self.ec2.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token'] self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint'] self.management_url = kwargs['endpoint']
class TestIdentityv2(utils.TestCommand):
def setUp(self):
super(TestIdentityv2, self).setUp()
self.app.client_manager.identity = FakeIdentityv2Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)

View File

@ -18,10 +18,9 @@ import copy
from openstackclient.identity.v2_0 import project from openstackclient.identity.v2_0 import project
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.identity.v2_0 import test_identity
class TestProject(test_identity.TestIdentityv2): class TestProject(identity_fakes.TestIdentityv2):
def setUp(self): def setUp(self):
super(TestProject, self).setUp() super(TestProject, self).setUp()

View File

@ -20,10 +20,9 @@ from openstackclient.common import exceptions
from openstackclient.identity.v2_0 import role from openstackclient.identity.v2_0 import role
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.identity.v2_0 import test_identity
class TestRole(test_identity.TestIdentityv2): class TestRole(identity_fakes.TestIdentityv2):
def setUp(self): def setUp(self):
super(TestRole, self).setUp() super(TestRole, self).setUp()

View File

@ -18,10 +18,9 @@ import copy
from openstackclient.identity.v2_0 import service from openstackclient.identity.v2_0 import service
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.identity.v2_0 import test_identity
class TestService(test_identity.TestIdentityv2): class TestService(identity_fakes.TestIdentityv2):
def setUp(self): def setUp(self):
super(TestService, self).setUp() super(TestService, self).setUp()

View File

@ -18,10 +18,9 @@ import copy
from openstackclient.identity.v2_0 import user from openstackclient.identity.v2_0 import user
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.identity.v2_0 import test_identity
class TestUser(test_identity.TestIdentityv2): class TestUser(identity_fakes.TestIdentityv2):
def setUp(self): def setUp(self):
super(TestUser, self).setUp() super(TestUser, self).setUp()

View File

@ -16,6 +16,7 @@
import mock import mock
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests import utils
domain_id = 'd1' domain_id = 'd1'
@ -104,3 +105,13 @@ class FakeIdentityv3Client(object):
self.users.resource_class = fakes.FakeResource(None, {}) self.users.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token'] self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint'] self.management_url = kwargs['endpoint']
class TestIdentityv3(utils.TestCommand):
def setUp(self):
super(TestIdentityv3, self).setUp()
self.app.client_manager.identity = FakeIdentityv3Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)

View File

@ -18,10 +18,9 @@ import copy
from openstackclient.identity.v3 import project from openstackclient.identity.v3 import project
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity.v3 import fakes as identity_fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes
from openstackclient.tests.identity.v3 import test_identity
class TestProject(test_identity.TestIdentityv3): class TestProject(identity_fakes.TestIdentityv3):
def setUp(self): def setUp(self):
super(TestProject, self).setUp() super(TestProject, self).setUp()

View File

@ -18,10 +18,9 @@ import copy
from openstackclient.identity.v3 import role from openstackclient.identity.v3 import role
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity.v3 import fakes as identity_fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes
from openstackclient.tests.identity.v3 import test_identity
class TestRole(test_identity.TestIdentityv3): class TestRole(identity_fakes.TestIdentityv3):
def setUp(self): def setUp(self):
super(TestRole, self).setUp() super(TestRole, self).setUp()

View File

@ -18,10 +18,9 @@ import copy
from openstackclient.identity.v3 import service from openstackclient.identity.v3 import service
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity.v3 import fakes as identity_fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes
from openstackclient.tests.identity.v3 import test_identity
class TestService(test_identity.TestIdentityv3): class TestService(identity_fakes.TestIdentityv3):
def setUp(self): def setUp(self):
super(TestService, self).setUp() super(TestService, self).setUp()

View File

@ -18,10 +18,9 @@ import copy
from openstackclient.identity.v3 import user from openstackclient.identity.v3 import user
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity.v3 import fakes as identity_fakes from openstackclient.tests.identity.v3 import fakes as identity_fakes
from openstackclient.tests.identity.v3 import test_identity
class TestUser(test_identity.TestIdentityv3): class TestUser(identity_fakes.TestIdentityv3):
def setUp(self): def setUp(self):
super(TestUser, self).setUp() super(TestUser, self).setUp()

View File

@ -1,51 +0,0 @@
# Copyright 2013 OpenStack, LLC.
#
# 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
from openstackclient.common import clientmanager
from openstackclient.image import client as image_client
from openstackclient.tests import utils
AUTH_TOKEN = "foobar"
AUTH_URL = "http://0.0.0.0"
class FakeClient(object):
def __init__(self, endpoint=None, **kwargs):
self.client = mock.MagicMock()
self.client.auth_token = AUTH_TOKEN
self.client.auth_url = AUTH_URL
class TestImage(utils.TestCase):
def setUp(self):
super(TestImage, self).setUp()
api_version = {"image": "2"}
image_client.API_VERSIONS = {
"2": "openstackclient.tests.image.test_image.FakeClient"
}
self.cm = clientmanager.ClientManager(token=AUTH_TOKEN,
url=AUTH_URL,
auth_url=AUTH_URL,
api_version=api_version)
def test_make_client(self):
self.assertEqual(self.cm.image.client.auth_token, AUTH_TOKEN)
self.assertEqual(self.cm.image.client.auth_url, AUTH_URL)

View File

@ -1,4 +1,4 @@
# Copyright 2013 Nebula Inc. # Copyright 2013 OpenStack, LLC.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
@ -12,20 +12,3 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
# #
from openstackclient.tests.identity.v2_0 import fakes
from openstackclient.tests import utils
AUTH_TOKEN = "foobar"
AUTH_URL = "http://0.0.0.0"
class TestIdentityv2(utils.TestCommand):
def setUp(self):
super(TestIdentityv2, self).setUp()
self.app.client_manager.identity = fakes.FakeIdentityv2Client(
endpoint=AUTH_URL,
token=AUTH_TOKEN,
)

View File

@ -0,0 +1,46 @@
# Copyright 2013 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.
#
import mock
from openstackclient.tests import fakes
from openstackclient.tests import utils
image_id = 'im1'
image_name = 'graven'
IMAGE = {
'id': image_id,
'name': image_name
}
class FakeImagev1Client(object):
def __init__(self, **kwargs):
self.images = mock.Mock()
self.images.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']
class TestImagev1(utils.TestCommand):
def setUp(self):
super(TestImagev1, self).setUp()
self.app.client_manager.image = FakeImagev1Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)

View File

@ -0,0 +1,63 @@
# Copyright 2013 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.
#
import copy
from openstackclient.image.v1 import image
from openstackclient.tests import fakes
from openstackclient.tests.image.v1 import fakes as image_fakes
class TestImage(image_fakes.TestImagev1):
def setUp(self):
super(TestImage, self).setUp()
# Get a shortcut to the ServerManager Mock
self.images_mock = self.app.client_manager.image.images
self.images_mock.reset_mock()
class TestImageDelete(TestImage):
def setUp(self):
super(TestImageDelete, self).setUp()
# This is the return value for utils.find_resource()
self.images_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(image_fakes.IMAGE),
loaded=True,
)
self.images_mock.delete.return_value = None
# Get the command object to test
self.cmd = image.DeleteImage(self.app, None)
def test_image_delete_no_options(self):
arglist = [
image_fakes.image_id,
]
verifylist = [
('image', image_fakes.image_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args)
self.images_mock.delete.assert_called_with(
image_fakes.image_id,
)

View File

@ -0,0 +1,14 @@
# Copyright 2013 OpenStack, LLC.
#
# 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.
#

View File

@ -0,0 +1,46 @@
# Copyright 2013 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.
#
import mock
from openstackclient.tests import fakes
from openstackclient.tests import utils
image_id = 'im1'
image_name = 'graven'
IMAGE = {
'id': image_id,
'name': image_name
}
class FakeImagev2Client(object):
def __init__(self, **kwargs):
self.images = mock.Mock()
self.images.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint']
class TestImagev2(utils.TestCommand):
def setUp(self):
super(TestImagev2, self).setUp()
self.app.client_manager.image = FakeImagev2Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)

View File

@ -0,0 +1,63 @@
# Copyright 2013 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.
#
import copy
from openstackclient.image.v1 import image
from openstackclient.tests import fakes
from openstackclient.tests.image.v2 import fakes as image_fakes
class TestImage(image_fakes.TestImagev2):
def setUp(self):
super(TestImage, self).setUp()
# Get a shortcut to the ServerManager Mock
self.images_mock = self.app.client_manager.image.images
self.images_mock.reset_mock()
class TestImageDelete(TestImage):
def setUp(self):
super(TestImageDelete, self).setUp()
# This is the return value for utils.find_resource()
self.images_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(image_fakes.IMAGE),
loaded=True,
)
self.images_mock.delete.return_value = None
# Get the command object to test
self.cmd = image.DeleteImage(self.app, None)
def test_image_delete_no_options(self):
arglist = [
image_fakes.image_id,
]
verifylist = [
('image', image_fakes.image_id),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
self.cmd.take_action(parsed_args)
self.images_mock.delete.assert_called_with(
image_fakes.image_id,
)

View File

@ -18,7 +18,7 @@ import mock
from openstackclient.common import clientmanager from openstackclient.common import clientmanager
from openstackclient.object.v1 import container from openstackclient.object.v1 import container
from openstackclient.tests.object import fakes as object_fakes from openstackclient.tests.object.v1 import fakes as object_fakes
from openstackclient.tests import utils from openstackclient.tests import utils

View File

@ -18,7 +18,7 @@ import mock
from openstackclient.common import clientmanager from openstackclient.common import clientmanager
from openstackclient.object.v1 import object as obj from openstackclient.object.v1 import object as obj
from openstackclient.tests.object import fakes as object_fakes from openstackclient.tests.object.v1 import fakes as object_fakes
from openstackclient.tests import utils from openstackclient.tests import utils

View File

@ -16,6 +16,9 @@
import mock import mock
from openstackclient.tests import fakes from openstackclient.tests import fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests import utils
volume_id = 'vvvvvvvv-vvvv-vvvv-vvvvvvvv' volume_id = 'vvvvvvvv-vvvv-vvvv-vvvvvvvv'
volume_name = 'nigel' volume_name = 'nigel'
@ -42,3 +45,18 @@ class FakeVolumev1Client(object):
self.services.resource_class = fakes.FakeResource(None, {}) self.services.resource_class = fakes.FakeResource(None, {})
self.auth_token = kwargs['token'] self.auth_token = kwargs['token']
self.management_url = kwargs['endpoint'] self.management_url = kwargs['endpoint']
class TestVolumev1(utils.TestCommand):
def setUp(self):
super(TestVolumev1, self).setUp()
self.app.client_manager.volume = FakeVolumev1Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)
self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client(
endpoint=fakes.AUTH_URL,
token=fakes.AUTH_TOKEN,
)

View File

@ -1,4 +1,4 @@
# Copyright 2013 OpenStack, LLC. # Copyright 2013 Nebula Inc.
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may # 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 # not use this file except in compliance with the License. You may obtain
@ -13,25 +13,256 @@
# under the License. # under the License.
# #
import copy
from openstackclient.tests import fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests import utils from openstackclient.tests.volume.v1 import fakes as volume_fakes
from openstackclient.tests.volume.v1 import fakes from openstackclient.volume.v1 import volume
AUTH_TOKEN = "foobar" class TestVolume(volume_fakes.TestVolumev1):
AUTH_URL = "http://0.0.0.0"
class TestVolumev1(utils.TestCommand):
def setUp(self): def setUp(self):
super(TestVolumev1, self).setUp() super(TestVolume, self).setUp()
self.app.client_manager.volume = fakes.FakeVolumev1Client( # Get a shortcut to the VolumeManager Mock
endpoint=AUTH_URL, self.volumes_mock = self.app.client_manager.volume.volumes
token=AUTH_TOKEN, self.volumes_mock.reset_mock()
# Get a shortcut to the TenantManager Mock
self.projects_mock = self.app.client_manager.identity.tenants
self.projects_mock.reset_mock()
# Get a shortcut to the UserManager Mock
self.users_mock = self.app.client_manager.identity.users
self.users_mock.reset_mock()
# TODO(dtroyer): The volume create tests are incomplete, only the minimal
# options and the options that require additional processing
# are implemented at this time.
class TestVolumeCreate(TestVolume):
def setUp(self):
super(TestVolumeCreate, self).setUp()
self.volumes_mock.create.return_value = fakes.FakeResource(
None,
copy.deepcopy(volume_fakes.VOLUME),
loaded=True,
) )
self.app.client_manager.identity = identity_fakes.FakeIdentityv2Client( # Get the command object to test
endpoint=AUTH_URL, self.cmd = volume.CreateVolume(self.app, None)
token=AUTH_TOKEN,
def test_volume_create_min_options(self):
arglist = [
'--size', str(volume_fakes.volume_size),
volume_fakes.volume_name,
]
verifylist = [
('size', volume_fakes.volume_size),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
#kwargs = {
# 'metadata': volume_fakes.volume_metadata,
#}
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
# project_id=, availability_zone=,
# metadata=, imageRef=)
self.volumes_mock.create.assert_called_with(
volume_fakes.volume_size,
None,
None,
volume_fakes.volume_name,
None,
None,
None,
None,
None,
None,
None,
) )
collist = (
'attach_status',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
)
self.assertEqual(columns, collist)
datalist = (
'detatched',
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
'',
volume_fakes.volume_size,
'',
)
self.assertEqual(data, datalist)
def test_volume_create_user_project_id(self):
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
# Return a user
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
arglist = [
'--size', str(volume_fakes.volume_size),
'--project', identity_fakes.project_id,
'--user', identity_fakes.user_id,
volume_fakes.volume_name,
]
verifylist = [
('size', volume_fakes.volume_size),
('project', identity_fakes.project_id),
('user', identity_fakes.user_id),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
#kwargs = {
# 'metadata': volume_fakes.volume_metadata,
#}
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
# project_id=, availability_zone=,
# metadata=, imageRef=)
self.volumes_mock.create.assert_called_with(
volume_fakes.volume_size,
None,
None,
volume_fakes.volume_name,
#volume_fakes.volume_description,
None,
None,
identity_fakes.user_id,
identity_fakes.project_id,
None,
None,
None,
)
collist = (
'attach_status',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
)
self.assertEqual(columns, collist)
datalist = (
'detatched',
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
'',
volume_fakes.volume_size,
'',
)
self.assertEqual(data, datalist)
def test_volume_create_user_project_name(self):
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
# Return a user
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
arglist = [
'--size', str(volume_fakes.volume_size),
'--project', identity_fakes.project_name,
'--user', identity_fakes.user_name,
volume_fakes.volume_name,
]
verifylist = [
('size', volume_fakes.volume_size),
('project', identity_fakes.project_name),
('user', identity_fakes.user_name),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
#kwargs = {
# 'metadata': volume_fakes.volume_metadata,
#}
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
# project_id=, availability_zone=,
# metadata=, imageRef=)
self.volumes_mock.create.assert_called_with(
volume_fakes.volume_size,
None,
None,
volume_fakes.volume_name,
#volume_fakes.volume_description,
None,
None,
identity_fakes.user_id,
identity_fakes.project_id,
None,
None,
None,
)
collist = (
'attach_status',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
)
self.assertEqual(columns, collist)
datalist = (
'detatched',
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
'',
volume_fakes.volume_size,
'',
)
self.assertEqual(data, datalist)

View File

@ -1,269 +0,0 @@
# Copyright 2013 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.
#
import copy
from openstackclient.tests import fakes
from openstackclient.tests.identity.v2_0 import fakes as identity_fakes
from openstackclient.tests.volume.v1 import fakes as volume_fakes
from openstackclient.tests.volume.v1 import test_volume
from openstackclient.volume.v1 import volume
class TestVolume(test_volume.TestVolumev1):
def setUp(self):
super(TestVolume, self).setUp()
# Get a shortcut to the VolumeManager Mock
self.volumes_mock = self.app.client_manager.volume.volumes
self.volumes_mock.reset_mock()
# Get a shortcut to the TenantManager Mock
self.projects_mock = self.app.client_manager.identity.tenants
self.projects_mock.reset_mock()
# Get a shortcut to the UserManager Mock
self.users_mock = self.app.client_manager.identity.users
self.users_mock.reset_mock()
# TODO(dtroyer): The volume create tests are incomplete, only the minimal
# options and the options that require additional processing
# are implemented at this time.
class TestVolumeCreate(TestVolume):
def setUp(self):
super(TestVolumeCreate, self).setUp()
self.volumes_mock.create.return_value = fakes.FakeResource(
None,
copy.deepcopy(volume_fakes.VOLUME),
loaded=True,
)
# Get the command object to test
self.cmd = volume.CreateVolume(self.app, None)
def test_volume_create_min_options(self):
arglist = [
'--size', str(volume_fakes.volume_size),
volume_fakes.volume_name,
]
verifylist = [
('size', volume_fakes.volume_size),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
#kwargs = {
# 'metadata': volume_fakes.volume_metadata,
#}
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
# project_id=, availability_zone=,
# metadata=, imageRef=)
self.volumes_mock.create.assert_called_with(
volume_fakes.volume_size,
None,
None,
volume_fakes.volume_name,
None,
None,
None,
None,
None,
None,
None,
)
collist = (
'attach_status',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
)
self.assertEqual(columns, collist)
datalist = (
'detatched',
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
'',
volume_fakes.volume_size,
'',
)
self.assertEqual(data, datalist)
def test_volume_create_user_project_id(self):
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
# Return a user
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
arglist = [
'--size', str(volume_fakes.volume_size),
'--project', identity_fakes.project_id,
'--user', identity_fakes.user_id,
volume_fakes.volume_name,
]
verifylist = [
('size', volume_fakes.volume_size),
('project', identity_fakes.project_id),
('user', identity_fakes.user_id),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
#kwargs = {
# 'metadata': volume_fakes.volume_metadata,
#}
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
# project_id=, availability_zone=,
# metadata=, imageRef=)
self.volumes_mock.create.assert_called_with(
volume_fakes.volume_size,
None,
None,
volume_fakes.volume_name,
#volume_fakes.volume_description,
None,
None,
identity_fakes.user_id,
identity_fakes.project_id,
None,
None,
None,
)
collist = (
'attach_status',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
)
self.assertEqual(columns, collist)
datalist = (
'detatched',
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
'',
volume_fakes.volume_size,
'',
)
self.assertEqual(data, datalist)
def test_volume_create_user_project_name(self):
# Return a project
self.projects_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.PROJECT),
loaded=True,
)
# Return a user
self.users_mock.get.return_value = fakes.FakeResource(
None,
copy.deepcopy(identity_fakes.USER),
loaded=True,
)
arglist = [
'--size', str(volume_fakes.volume_size),
'--project', identity_fakes.project_name,
'--user', identity_fakes.user_name,
volume_fakes.volume_name,
]
verifylist = [
('size', volume_fakes.volume_size),
('project', identity_fakes.project_name),
('user', identity_fakes.user_name),
('name', volume_fakes.volume_name),
]
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
# DisplayCommandBase.take_action() returns two tuples
columns, data = self.cmd.take_action(parsed_args)
# Set expected values
#kwargs = {
# 'metadata': volume_fakes.volume_metadata,
#}
# VolumeManager.create(size, snapshot_id=, source_volid=,
# display_name=, display_description=,
# volume_type=, user_id=,
# project_id=, availability_zone=,
# metadata=, imageRef=)
self.volumes_mock.create.assert_called_with(
volume_fakes.volume_size,
None,
None,
volume_fakes.volume_name,
#volume_fakes.volume_description,
None,
None,
identity_fakes.user_id,
identity_fakes.project_id,
None,
None,
None,
)
collist = (
'attach_status',
'display_description',
'display_name',
'id',
'properties',
'size',
'status',
)
self.assertEqual(columns, collist)
datalist = (
'detatched',
volume_fakes.volume_description,
volume_fakes.volume_name,
volume_fakes.volume_id,
'',
volume_fakes.volume_size,
'',
)
self.assertEqual(data, datalist)