Removed some un-needed code, and started adding tests for show(), which I forgot\!
This commit is contained in:
@@ -13,9 +13,10 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from webob import exc
|
||||
import webob.exc
|
||||
|
||||
from nova import compute
|
||||
from nova import exception
|
||||
from nova import flags
|
||||
from nova import utils
|
||||
from nova import wsgi
|
||||
@@ -39,11 +40,6 @@ class Controller(wsgi.Controller):
|
||||
},
|
||||
}
|
||||
|
||||
_builder_dispatch = {
|
||||
"1.0": images_view.ViewBuilderV10,
|
||||
"1.1": images_view.ViewBuilderV11,
|
||||
}
|
||||
|
||||
def __init__(self, image_service=None, compute_service=None):
|
||||
"""
|
||||
Initialize new `ImageController`.
|
||||
@@ -60,7 +56,7 @@ class Controller(wsgi.Controller):
|
||||
"""
|
||||
Return an index listing of images available to the request.
|
||||
|
||||
@param req: `webob.Request` object
|
||||
@param req: `wsgi.Request` object
|
||||
"""
|
||||
context = req.environ['nova.context']
|
||||
images = self.__image.index(context)
|
||||
@@ -71,31 +67,38 @@ class Controller(wsgi.Controller):
|
||||
"""
|
||||
Return a detailed index listing of images available to the request.
|
||||
|
||||
@param req: `webob.Request` object.
|
||||
@param req: `wsgi.Request` object.
|
||||
"""
|
||||
context = req.environ['nova.context']
|
||||
images = self.__image.detail(context)
|
||||
build = self.get_builder(req).build
|
||||
return dict(images=[build(image, True) for image in images])
|
||||
|
||||
def show(self, req, image_id):
|
||||
def show(self, req, id):
|
||||
"""
|
||||
Return detailed information about a specific image.
|
||||
|
||||
@param req: `webob.Request` object
|
||||
@param image_id: Image identifier (integer)
|
||||
@param req: `wsgi.Request` object
|
||||
@param id: Image identifier (integer)
|
||||
"""
|
||||
image_id = id
|
||||
context = req.environ['nova.context']
|
||||
image = self.__image.show(context, image_id)
|
||||
return self.get_builder().build(req, image, True)
|
||||
|
||||
def delete(self, req, image_id):
|
||||
try:
|
||||
image = self.__image.show(context, image_id)
|
||||
except exception.NotFound:
|
||||
raise webob.exc.HTTPNotFound
|
||||
|
||||
return self.get_builder(req).build(image, True)
|
||||
|
||||
def delete(self, req, id):
|
||||
"""
|
||||
Delete an image, if allowed.
|
||||
|
||||
@param req: `webob.Request` object
|
||||
@param image_id: Image identifier (integer)
|
||||
@param req: `wsgi.Request` object
|
||||
@param id: Image identifier (integer)
|
||||
"""
|
||||
image_id = id
|
||||
context = req.environ['nova.context']
|
||||
self.__image.delete(context, image_id)
|
||||
return exc.HTTPNoContent()
|
||||
@@ -104,7 +107,7 @@ class Controller(wsgi.Controller):
|
||||
"""
|
||||
Snapshot a server instance and save the image.
|
||||
|
||||
@param req: `webob.Request` object
|
||||
@param req: `wsgi.Request` object
|
||||
"""
|
||||
context = req.environ['nova.context']
|
||||
body = req.body
|
||||
|
@@ -235,6 +235,67 @@ class ImageControllerWithGlanceServiceTest(test.TestCase):
|
||||
|
||||
self.assertEqual(len(response_list), len(self.IMAGE_FIXTURES))
|
||||
|
||||
def test_get_image(self):
|
||||
request = webob.Request.blank('/v1.0/images/23g2ogk23k4hhkk4k42l')
|
||||
response = request.get_response(fakes.wsgi_app())
|
||||
|
||||
actual_image = json.loads(response.body)
|
||||
|
||||
expected = self.IMAGE_FIXTURES[0]
|
||||
expected_image = {
|
||||
"id": expected["id"],
|
||||
"name": expected["name"],
|
||||
"updated": expected["updated_at"],
|
||||
"created": expected["created_at"],
|
||||
"status": expected["status"],
|
||||
}
|
||||
|
||||
self.assertEqual(expected_image, actual_image)
|
||||
|
||||
def test_get_image_v1_1(self):
|
||||
request = webob.Request.blank('/v1.1/images/23g2ogk23k4hhkk4k42l')
|
||||
response = request.get_response(fakes.wsgi_app())
|
||||
|
||||
actual_image = json.loads(response.body)
|
||||
|
||||
expected = self.IMAGE_FIXTURES[0]
|
||||
href = "http://localhost/v1.1/images/%s" % expected["id"]
|
||||
|
||||
expected_image = {
|
||||
"id": expected["id"],
|
||||
"name": expected["name"],
|
||||
"updated": expected["updated_at"],
|
||||
"created": expected["created_at"],
|
||||
"status": expected["status"],
|
||||
"links": [{
|
||||
"rel": "self",
|
||||
"href": href,
|
||||
},
|
||||
{
|
||||
"rel": "bookmark",
|
||||
"type": "application/json",
|
||||
"href": href,
|
||||
},
|
||||
{
|
||||
"rel": "bookmark",
|
||||
"type": "application/xml",
|
||||
"href": href,
|
||||
}],
|
||||
}
|
||||
|
||||
self.assertEqual(expected_image, actual_image)
|
||||
|
||||
def test_get_image_404(self):
|
||||
request = webob.Request.blank('/v1.0/images/NonExistantImage')
|
||||
response = request.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(404, response.status_int)
|
||||
self.assertEqual("", response.body)
|
||||
|
||||
def test_get_image_v1_1_404(self):
|
||||
request = webob.Request.blank('/v1.1/images/NonExistantImage')
|
||||
response = request.get_response(fakes.wsgi_app())
|
||||
self.assertEqual(404, response.status_int)
|
||||
|
||||
def test_get_image_index_v1_1(self):
|
||||
request = webob.Request.blank('/v1.1/images')
|
||||
response = request.get_response(fakes.wsgi_app())
|
||||
|
Reference in New Issue
Block a user