189 |
189 |
self.assertEqual(r['id'], img0['id'])
|
190 |
190 |
self.assert_dicts_are_equal(r, example_images_detailed[0])
|
191 |
191 |
|
192 |
|
@patch('%s.perform_request' % khttp, return_value=FR())
|
193 |
|
def test_register(self, PR):
|
|
192 |
@patch('%s.set_header' % image_pkg, return_value=FR())
|
|
193 |
@patch('%s.post' % image_pkg, return_value=FR())
|
|
194 |
def test_register(self, post, SH):
|
194 |
195 |
img0 = example_images_detailed[0]
|
195 |
196 |
img0_location = img0['location']
|
196 |
197 |
img0_name = 'A new img0 name'
|
197 |
|
self.client.register(img0_name, img0_location)
|
198 |
|
self.assertEqual(self.client.http_client.url, self.url)
|
199 |
|
self.assertEqual(self.client.http_client.path, '/images/')
|
200 |
|
(method, data, headers, params) = PR.call_args[0]
|
201 |
|
self.assertEqual(method, 'post')
|
202 |
|
self.assertTrue(0 == len(params))
|
203 |
|
|
204 |
|
val = 'Some random value'
|
205 |
|
param_dict = dict(
|
206 |
|
id=val,
|
207 |
|
store=val,
|
208 |
|
disk_format=val,
|
209 |
|
container_format=val,
|
210 |
|
size=val,
|
211 |
|
checksum=val,
|
212 |
|
is_public=val,
|
213 |
|
owner=val)
|
214 |
|
for key in param_dict.keys():
|
215 |
|
param = {key: val}
|
216 |
|
self.client.register(img0_name, img0_location, params=param)
|
217 |
|
(method, data, a_headers, a_params) = PR.call_args[0]
|
218 |
|
key = 'x-image-meta-%s' % key.replace('_', '-')
|
219 |
|
self.assertEqual(a_headers[key], val)
|
220 |
|
self.client.register(img0_name, img0_location, params=param_dict)
|
221 |
|
(method, data, a_headers, a_params) = PR.call_args[0]
|
222 |
|
self.assertEqual(len(param_dict), len(a_headers))
|
223 |
|
for key, val in param_dict.items():
|
224 |
|
key = 'x-image-meta-%s' % key.replace('_', '-')
|
225 |
|
self.assertEqual(a_headers[key], val)
|
226 |
|
|
227 |
|
props = dict(key0='val0', key2='val2', key3='val3')
|
228 |
|
self.client.register(img0_name, img0_location, properties=props)
|
229 |
|
(method, data, a_headers, a_params) = PR.call_args[0]
|
230 |
|
for k, v in props.items():
|
231 |
|
self.assertEquals(a_headers['X-Image-Meta-Property-%s' % k], v)
|
|
198 |
prfx = 'x-image-meta-'
|
|
199 |
proprfx = 'x-image-meta-property-'
|
|
200 |
keys = [
|
|
201 |
'id', 'store', 'dist_format', 'container_format',
|
|
202 |
'size', 'checksum', 'is_public', 'owner']
|
|
203 |
for args in product(
|
|
204 |
('v_id', None), ('v_store', None),
|
|
205 |
('v_dist_format', None), ('v_container_format', None),
|
|
206 |
('v_size', None), ('v_checksum', None),
|
|
207 |
('v_is_public', None), ('v_owner', None)):
|
|
208 |
params = dict()
|
|
209 |
async_headers = dict()
|
|
210 |
props = dict()
|
|
211 |
for i, k in enumerate(keys):
|
|
212 |
if args[i]:
|
|
213 |
params[k] = args[i]
|
|
214 |
async_headers['%s%s' % (prfx, k)] = args[i]
|
|
215 |
props['%s%s' % (proprfx, args[i])] = k
|
|
216 |
async_headers.update(props)
|
|
217 |
self.client.register(
|
|
218 |
img0_name, img0_location,
|
|
219 |
params=params, properties=props)
|
|
220 |
self.assertEqual(
|
|
221 |
post.mock_calls[-1],
|
|
222 |
call('/images/', async_headers=async_headers, success=200))
|
|
223 |
self.assertEqual(SH.mock_calls[-2:], [
|
|
224 |
call('X-Image-Meta-Name', img0_name),
|
|
225 |
call('X-Image-Meta-Location', img0_location)])
|
232 |
226 |
|
233 |
227 |
@patch('%s.perform_request' % khttp, return_value=FR())
|
234 |
228 |
def test_set_members(self, PR):
|