Merge "Convert Availability Zone testing to httpretty"

This commit is contained in:
Jenkins 2014-05-22 02:11:19 +00:00 committed by Gerrit Code Review
commit c7c653d513
3 changed files with 111 additions and 16 deletions

View File

@ -0,0 +1,99 @@
# 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 httpretty
from novaclient.openstack.common import jsonutils
from novaclient.tests.fixture_data import base
class V1(base.Fixture):
base_url = 'os-availability-zone'
zone_info_key = 'availabilityZoneInfo'
zone_name_key = 'zoneName'
zone_state_key = 'zoneState'
def setUp(self):
super(V1, self).setUp()
get_os_availability_zone = {
self.zone_info_key: [
{
self.zone_name_key: "zone-1",
self.zone_state_key: {"available": True},
"hosts": None
},
{
self.zone_name_key: "zone-2",
self.zone_state_key: {"available": False},
"hosts": None
}
]
}
httpretty.register_uri(httpretty.GET, self.url(),
body=jsonutils.dumps(get_os_availability_zone),
content_type='application/json')
get_os_zone_detail = {
self.zone_info_key: [
{
self.zone_name_key: "zone-1",
self.zone_state_key: {"available": True},
"hosts": {
"fake_host-1": {
"nova-compute": {
"active": True,
"available": True,
"updated_at": '2012-12-26 14:45:25'
}
}
}
},
{
self.zone_name_key: "internal",
self.zone_state_key: {"available": True},
"hosts": {
"fake_host-1": {
"nova-sched": {
"active": True,
"available": True,
"updated_at": '2012-12-26 14:45:25'
}
},
"fake_host-2": {
"nova-network": {
"active": True,
"available": False,
"updated_at": '2012-12-26 14:45:24'
}
}
}
},
{
self.zone_name_key: "zone-2",
self.zone_state_key: {"available": False},
"hosts": None
}
]
}
httpretty.register_uri(httpretty.GET, self.url('detail'),
body=jsonutils.dumps(get_os_zone_detail),
content_type='application/json')
class V3(V1):
zone_info_key = 'availability_zone_info'
zone_name_key = 'zone_name'
zone_state_key = 'zone_state'

View File

@ -16,24 +16,24 @@
import six
from novaclient.tests.fixture_data import availability_zones as data
from novaclient.tests.fixture_data import client
from novaclient.tests import utils
from novaclient.tests.v1_1 import fakes
from novaclient.v1_1 import availability_zones
class AvailabilityZoneTest(utils.TestCase):
class AvailabilityZoneTest(utils.FixturedTestCase):
# NOTE(cyeoh): import shell here so the V3 version of
# this class can inherit off the v3 version of shell
from novaclient.v1_1 import shell # noqa
client_fixture_class = client.V1
data_fixture_class = data.V1
def setUp(self):
super(AvailabilityZoneTest, self).setUp()
self.cs = self._get_fake_client()
self.availability_zone_type = self._get_availability_zone_type()
def _get_fake_client(self):
return fakes.FakeClient()
def _get_availability_zone_type(self):
return availability_zones.AvailabilityZone
@ -43,7 +43,7 @@ class AvailabilityZoneTest(utils.TestCase):
def test_list_availability_zone(self):
zones = self.cs.availability_zones.list(detailed=False)
self.cs.assert_called('GET', '/os-availability-zone')
self.assert_called('GET', '/os-availability-zone')
for zone in zones:
self.assertIsInstance(zone, self.availability_zone_type)
@ -63,7 +63,7 @@ class AvailabilityZoneTest(utils.TestCase):
def test_detail_availability_zone(self):
zones = self.cs.availability_zones.list(detailed=True)
self.cs.assert_called('GET', '/os-availability-zone/detail')
self.assert_called('GET', '/os-availability-zone/detail')
for zone in zones:
self.assertIsInstance(zone, self.availability_zone_type)

View File

@ -14,25 +14,21 @@
# License for the specific language governing permissions and limitations
# under the License.
from novaclient.tests.fixture_data import availability_zones as data
from novaclient.tests.fixture_data import client
from novaclient.tests.v1_1 import test_availability_zone
from novaclient.tests.v3 import fakes
from novaclient.v3 import availability_zones
class AvailabilityZoneTest(test_availability_zone.AvailabilityZoneTest):
from novaclient.v3 import shell # noqa
def setUp(self):
super(AvailabilityZoneTest, self).setUp()
self.cs = self._get_fake_client()
self.availability_zone_type = self._get_availability_zone_type()
client_fixture_class = client.V3
data_fixture_class = data.V3
def _assertZone(self, zone, name, status):
self.assertEqual(zone.zone_name, name)
self.assertEqual(zone.zone_state, status)
def _get_fake_client(self):
return fakes.FakeClient()
def _get_availability_zone_type(self):
return availability_zones.AvailabilityZone