def _action_test(self, container, action, ident_field,
mock_container_action, status_code, query_param=''):
test_container_obj = objects.Container(self.context, **container)
ident = container.get(ident_field)
get_by_ident_loc = 'zun.objects.Container.get_by_%s' % ident_field
with patch(get_by_ident_loc) as mock_get_by_indent:
mock_get_by_indent.return_value = test_container_obj
response = self.post('/v1/containers/%s/%s/?%s' %
(ident, action, query_param))
self.assertEqual(status_code, response.status_int)
# Only PUT should work, others like GET should fail
self.assertRaises(AppError, self.get,
('/v1/containers/%s/%s/' %
(ident, action)))
if query_param:
value = query_param.split('=')[1]
mock_container_action.assert_called_once_with(
mock.ANY, test_container_obj, value)
else:
mock_container_action.assert_called_once_with(
mock.ANY, test_container_obj)
评论列表
文章目录