There was an exceptionally large amount of rote use of _get_regexes throughout the samples tests, which doesn't provide any additional explicitness in what's happening, and only couples the tests to the base class in less useful ways. Instead, when we call _verify_response, always also use the base vanilla regexes for matching tests. We also needed to add a few more variables to the list which always need to be reset before testing against the static samples, because uuids are often generated on the fly for the tests. Lastly, test_keypairs needed some test specific surgery. It is so highly normalized (with private test methods that take **kwargs) at this point that it's not really clear that it's testing useful things any more. This really needs denormalization. Change-Id: I165b0f3aa2132373cb59982a5a5ded37b4fa1b52
85 lines
3.5 KiB
Python
85 lines
3.5 KiB
Python
# Copyright 2012 Nebula, Inc.
|
|
# Copyright 2013 IBM Corp.
|
|
#
|
|
# 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 oslo_config import cfg
|
|
|
|
from nova.tests.functional.api_sample_tests import api_sample_base
|
|
from nova.tests.unit.image import fake
|
|
|
|
CONF = cfg.CONF
|
|
CONF.import_opt('osapi_compute_extension',
|
|
'nova.api.openstack.compute.legacy_v2.extensions')
|
|
|
|
|
|
class ImagesSampleJsonTest(api_sample_base.ApiSampleTestBaseV21):
|
|
sample_dir = 'images'
|
|
# TODO(gmann): This will be removed once all API tests runs for
|
|
# all extension enable.
|
|
all_extensions = True
|
|
|
|
def test_images_list(self):
|
|
# Get api sample of images get list request.
|
|
response = self._do_get('images')
|
|
self._verify_response('images-list-get-resp', {}, response, 200)
|
|
|
|
def test_image_get(self):
|
|
# Get api sample of one single image details request.
|
|
image_id = fake.get_valid_image_id()
|
|
response = self._do_get('images/%s' % image_id)
|
|
subs = {'image_id': image_id}
|
|
self._verify_response('image-get-resp', subs, response, 200)
|
|
|
|
def test_images_details(self):
|
|
# Get api sample of all images details request.
|
|
response = self._do_get('images/detail')
|
|
self._verify_response('images-details-get-resp', {}, response, 200)
|
|
|
|
def test_image_metadata_get(self):
|
|
# Get api sample of an image metadata request.
|
|
image_id = fake.get_valid_image_id()
|
|
response = self._do_get('images/%s/metadata' % image_id)
|
|
subs = {'image_id': image_id}
|
|
self._verify_response('image-metadata-get-resp', subs, response, 200)
|
|
|
|
def test_image_metadata_post(self):
|
|
# Get api sample to update metadata of an image metadata request.
|
|
image_id = fake.get_valid_image_id()
|
|
response = self._do_post(
|
|
'images/%s/metadata' % image_id,
|
|
'image-metadata-post-req', {})
|
|
self._verify_response('image-metadata-post-resp', {}, response, 200)
|
|
|
|
def test_image_metadata_put(self):
|
|
# Get api sample of image metadata put request.
|
|
image_id = fake.get_valid_image_id()
|
|
response = self._do_put('images/%s/metadata' %
|
|
(image_id), 'image-metadata-put-req', {})
|
|
self._verify_response('image-metadata-put-resp', {}, response, 200)
|
|
|
|
def test_image_meta_key_get(self):
|
|
# Get api sample of an image metadata key request.
|
|
image_id = fake.get_valid_image_id()
|
|
key = "kernel_id"
|
|
response = self._do_get('images/%s/metadata/%s' % (image_id, key))
|
|
self._verify_response('image-meta-key-get', {}, response, 200)
|
|
|
|
def test_image_meta_key_put(self):
|
|
# Get api sample of image metadata key put request.
|
|
image_id = fake.get_valid_image_id()
|
|
key = "auto_disk_config"
|
|
response = self._do_put('images/%s/metadata/%s' % (image_id, key),
|
|
'image-meta-key-put-req', {})
|
|
self._verify_response('image-meta-key-put-resp', {}, response, 200)
|