Merge "Changes to allow image upload with V2 api"

This commit is contained in:
Jenkins
2013-07-31 19:10:12 +00:00
committed by Gerrit Code Review
2 changed files with 28 additions and 0 deletions
+13
View File
@@ -88,6 +88,19 @@ class Controller(object):
else:
return body
def upload(self, image_id, image_data):
"""
Upload the data for an image.
:param image_id: ID of the image to upload data for.
:param image_data: File-like object supplying the data to upload.
"""
url = '/v2/images/%s/file' % image_id
hdrs = {'Content-Type': 'application/octet-stream'}
self.http_client.raw_request('PUT', url,
headers=hdrs,
body=image_data)
def delete(self, image_id):
"""Delete an image."""
self.http_client.json_request('DELETE', 'v2/images/%s' % image_id)
+15
View File
@@ -105,6 +105,12 @@ fixtures = {
},
),
},
'/v2/images/606b0e88-7c5a-4d54-b5bb-046105d4de6f/file': {
'PUT': (
{},
'',
),
},
'/v2/images/5cc4bebc-db27-11e1-a1eb-080027cbe205/file': {
'GET': (
{},
@@ -355,6 +361,15 @@ class TestController(testtools.TestCase):
None)]
self.assertEqual(self.api.calls, expect)
def test_data_upload(self):
image_data = 'CCC'
image_id = '606b0e88-7c5a-4d54-b5bb-046105d4de6f'
self.controller.upload(image_id, image_data)
expect = [('PUT', '/v2/images/%s/file' % image_id,
{'Content-Type': 'application/octet-stream'},
image_data)]
self.assertEqual(self.api.calls, expect)
def test_data_without_checksum(self):
body = self.controller.data('5cc4bebc-db27-11e1-a1eb-080027cbe205',
do_checksum=False)