From 2fef2e6c4f9fbbac795740ddfec57ba193029d03 Mon Sep 17 00:00:00 2001 From: Dan Smith Date: Fri, 16 Jul 2021 11:33:33 -0700 Subject: [PATCH] Add api_patch() to SynchronousAPIBase This makes it easier to run PATCH operations against the API from synchronous functional tests. It also adds a status assertion to one of the upload methods which makes it easier to determine when an operation was denied. Change-Id: Ie67cd0ada86c03d8eac06dfa3d0730d329591628 --- glance/tests/functional/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/glance/tests/functional/__init__.py b/glance/tests/functional/__init__.py index c516c79e92..0dfdb11227 100644 --- a/glance/tests/functional/__init__.py +++ b/glance/tests/functional/__init__.py @@ -1695,6 +1695,21 @@ class SynchronousAPIBase(test_utils.BaseTestCase): """ return self.api_request('DELETE', url, headers=headers) + def api_patch(self, url, *patches, headers=None): + """Perform a PATCH request against the API. + + :param url: The *path* part of the URL to call (i.e. /v2/images) + :param patches: One or more patch dicts + :param headers: Optional updates to the default set of headers + :returns: A webob.Response object + """ + if not headers: + headers = {} + headers['Content-Type'] = \ + 'application/openstack-images-v2.1-json-patch' + return self.api_request('PATCH', url, headers=headers, + json=list(patches)) + def _import_copy(self, image_id, stores): """Do an import of image_id to the given stores.""" body = {'method': {'name': 'copy-image'}, @@ -1731,6 +1746,7 @@ class SynchronousAPIBase(test_utils.BaseTestCase): json={'name': 'foo', 'container_format': 'bare', 'disk_format': 'raw'}) + self.assertEqual(201, resp.status_code, resp.text) image = jsonutils.loads(resp.text) if data_iter: