Preparing for Heat tests

Required for blueprint: heat-ui

Change-Id: Ibac4ab7d238ab946a096767218faf9e222699cb6
This commit is contained in:
Steve Baker 2013-05-17 12:46:56 +12:00
parent c949b6fbd5
commit 53d2d9352b
4 changed files with 86 additions and 1 deletions

View File

@ -0,0 +1,32 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# 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 django.conf import settings
from django.test.utils import override_settings
from openstack_dashboard import api
from openstack_dashboard.test import helpers as test
class HeatApiTests(test.APITestCase):
def test_stack_list(self):
api_stacks = self.stacks.list()
heatclient = self.stub_heatclient()
heatclient.stacks = self.mox.CreateMockAnything()
heatclient.stacks.list().AndReturn(iter(api_stacks))
self.mox.ReplayAll()
stacks = api.heat.stacks_list(self.request)
self.assertItemsEqual(stacks, api_stacks)

View File

@ -35,6 +35,7 @@ from novaclient.v1_1 import client as nova_client
from quantumclient.v2_0 import client as quantum_client
from swiftclient import client as swift_client
from cinderclient import client as cinder_client
from heatclient import client as heat_client
import httplib2
import mox
@ -246,6 +247,7 @@ class APITestCase(TestCase):
self._original_novaclient = api.nova.novaclient
self._original_quantumclient = api.quantum.quantumclient
self._original_cinderclient = api.cinder.cinderclient
self._original_heatclient = api.heat.heatclient
# Replace the clients with our stubs.
api.glance.glanceclient = lambda request: self.stub_glanceclient()
@ -253,6 +255,7 @@ class APITestCase(TestCase):
api.nova.novaclient = lambda request: self.stub_novaclient()
api.quantum.quantumclient = lambda request: self.stub_quantumclient()
api.cinder.cinderclient = lambda request: self.stub_cinderclient()
api.heat.heatclient = lambda request: self.stub_heatclient()
def tearDown(self):
super(APITestCase, self).tearDown()
@ -261,6 +264,7 @@ class APITestCase(TestCase):
api.keystone.keystoneclient = self._original_keystoneclient
api.quantum.quantumclient = self._original_quantumclient
api.cinder.cinderclient = self._original_cinderclient
api.heat.heatclient = self._original_heatclient
def stub_novaclient(self):
if not hasattr(self, "novaclient"):
@ -310,6 +314,12 @@ class APITestCase(TestCase):
expected_calls -= 1
return self.swiftclient
def stub_heatclient(self):
if not hasattr(self, "heatclient"):
self.mox.StubOutWithMock(heat_client, 'Client')
self.heatclient = self.mox.CreateMock(heat_client.Client)
return self.heatclient
@unittest.skipUnless(os.environ.get('WITH_SELENIUM', False),
"The WITH_SELENIUM env variable is not set.")

View File

@ -0,0 +1,41 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# 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 heatclient.v1.stacks import Stack, StackManager
from .utils import TestDataContainer
def data(TEST):
TEST.stacks = TestDataContainer()
# Stacks
stack1 = {
"description": "No description",
"links": [{
"href": "http://192.168.1.70:8004/v1/"
"051c727ee67040d6a7b7812708485a97/"
"stacks/stack-1211-38/"
"05b4f39f-ea96-4d91-910c-e758c078a089",
"rel": "self"
}],
"stack_status_reason": "Stack successfully created",
"stack_name": "stack-1211-38",
"creation_time": "2013-04-22T00:11:39Z",
"updated_time": "2013-04-22T00:11:39Z",
"stack_status": "CREATE_COMPLETE",
"id": "05b4f39f-ea96-4d91-910c-e758c078a089"
}
stack = Stack(StackManager(None), stack1)
TEST.stacks.add(stack)

View File

@ -20,6 +20,7 @@ def load_test_data(load_onto=None):
from . import nova_data
from . import quantum_data
from . import swift_data
from . import heat_data
# The order of these loaders matters, some depend on others.
loaders = (exceptions.data,
@ -27,7 +28,8 @@ def load_test_data(load_onto=None):
glance_data.data,
nova_data.data,
quantum_data.data,
swift_data.data)
swift_data.data,
heat_data.data)
if load_onto:
for data_func in loaders:
data_func(load_onto)