Merge "Remove location check from V2 client"
This commit is contained in:
@@ -1014,17 +1014,13 @@ class TestController(testtools.TestCase):
|
|||||||
|
|
||||||
def test_location_ops_when_server_disabled_location_ops(self):
|
def test_location_ops_when_server_disabled_location_ops(self):
|
||||||
# Location operations should not be allowed if server has not
|
# Location operations should not be allowed if server has not
|
||||||
# enabled location related operations
|
# enabled location related operations. There is no need to check it
|
||||||
|
# when do location add, because the check would be done in server side.
|
||||||
image_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
|
image_id = '3a4560a1-e585-443e-9b39-553b46ec92d1'
|
||||||
estr = 'The administrator has disabled API access to image locations'
|
estr = 'The administrator has disabled API access to image locations'
|
||||||
url = 'http://bar.com/'
|
url = 'http://bar.com/'
|
||||||
meta = {'bar': 'barmeta'}
|
meta = {'bar': 'barmeta'}
|
||||||
|
|
||||||
e = self.assertRaises(exc.HTTPBadRequest,
|
|
||||||
self.controller.add_location,
|
|
||||||
image_id, url, meta)
|
|
||||||
self.assertIn(estr, str(e))
|
|
||||||
|
|
||||||
e = self.assertRaises(exc.HTTPBadRequest,
|
e = self.assertRaises(exc.HTTPBadRequest,
|
||||||
self.controller.delete_locations,
|
self.controller.delete_locations,
|
||||||
image_id, set([url]))
|
image_id, set([url]))
|
||||||
@@ -1052,20 +1048,19 @@ class TestController(testtools.TestCase):
|
|||||||
add_patch = {'path': '/locations/-', 'value': new_loc, 'op': 'add'}
|
add_patch = {'path': '/locations/-', 'value': new_loc, 'op': 'add'}
|
||||||
self.controller.add_location(image_id, **new_loc)
|
self.controller.add_location(image_id, **new_loc)
|
||||||
self.assertEqual(self.api.calls, [
|
self.assertEqual(self.api.calls, [
|
||||||
self._empty_get(image_id),
|
|
||||||
self._patch_req(image_id, [add_patch]),
|
self._patch_req(image_id, [add_patch]),
|
||||||
self._empty_get(image_id)
|
self._empty_get(image_id)
|
||||||
])
|
])
|
||||||
|
|
||||||
def test_add_duplicate_location(self):
|
@mock.patch.object(images.Controller, '_send_image_update_request',
|
||||||
|
side_effect=exc.HTTPBadRequest)
|
||||||
|
def test_add_duplicate_location(self, mock_request):
|
||||||
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d8'
|
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d8'
|
||||||
new_loc = {'url': 'http://foo.com/', 'metadata': {'foo': 'newfoo'}}
|
new_loc = {'url': 'http://foo.com/', 'metadata': {'foo': 'newfoo'}}
|
||||||
err_str = 'A location entry at %s already exists' % new_loc['url']
|
|
||||||
|
|
||||||
err = self.assertRaises(exc.HTTPConflict,
|
self.assertRaises(exc.HTTPBadRequest,
|
||||||
self.controller.add_location,
|
self.controller.add_location,
|
||||||
image_id, **new_loc)
|
image_id, **new_loc)
|
||||||
self.assertIn(err_str, str(err))
|
|
||||||
|
|
||||||
def test_remove_location(self):
|
def test_remove_location(self):
|
||||||
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d8'
|
image_id = 'a2b83adc-888e-11e3-8872-78acc0b951d8'
|
||||||
|
@@ -306,12 +306,6 @@ class Controller(object):
|
|||||||
:param metadata: Metadata associated with the location.
|
:param metadata: Metadata associated with the location.
|
||||||
:returns: The updated image
|
:returns: The updated image
|
||||||
"""
|
"""
|
||||||
image = self._get_image_with_locations_or_fail(image_id)
|
|
||||||
url_list = [l['url'] for l in image.locations]
|
|
||||||
if url in url_list:
|
|
||||||
err_str = 'A location entry at %s already exists' % url
|
|
||||||
raise exc.HTTPConflict(err_str)
|
|
||||||
|
|
||||||
add_patch = [{'op': 'add', 'path': '/locations/-',
|
add_patch = [{'op': 'add', 'path': '/locations/-',
|
||||||
'value': {'url': url, 'metadata': metadata}}]
|
'value': {'url': url, 'metadata': metadata}}]
|
||||||
self._send_image_update_request(image_id, add_patch)
|
self._send_image_update_request(image_id, add_patch)
|
||||||
|
Reference in New Issue
Block a user