How to use _create_with_data method in tempest

Best Python code snippet using tempest_python

images_client.py

Source:images_client.py Github

copy

Full Screen

...19from tempest.lib import exceptions as lib_exc20CHUNKSIZE = 1024 * 64 # 64kB21class ImagesClient(rest_client.RestClient):22 api_version = "v1"23 def _create_with_data(self, headers, data):24 # We are going to do chunked transfert, so split the input data25 # info fixed-sized chunks.26 headers['Content-Type'] = 'application/octet-stream'27 data = iter(functools.partial(data.read, CHUNKSIZE), b'')28 resp, body = self.request('POST', 'images',29 headers=headers, body=data, chunked=True)30 self._error_checker(resp, body)31 body = json.loads(body)32 return rest_client.ResponseBody(resp, body)33 def _update_with_data(self, image_id, headers, data):34 # We are going to do chunked transfert, so split the input data35 # info fixed-sized chunks.36 headers['Content-Type'] = 'application/octet-stream'37 data = iter(functools.partial(data.read, CHUNKSIZE), b'')38 url = 'images/%s' % image_id39 resp, body = self.request('PUT', url, headers=headers,40 body=data, chunked=True)41 self._error_checker(resp, body)42 body = json.loads(body)43 return rest_client.ResponseBody(resp, body)44 @property45 def http(self):46 if self._http is None:47 self._http = self._get_http()48 return self._http49 def create_image(self, data=None, headers=None):50 """Create an image.51 For a full list of available parameters, please refer to the official52 API reference:53 http://developer.openstack.org/api-ref-image-v1.html#createImage-v154 """55 if headers is None:56 headers = {}57 if data is not None:58 return self._create_with_data(headers, data)59 resp, body = self.post('images', None, headers)60 self.expected_success(201, resp.status)61 body = json.loads(body)62 return rest_client.ResponseBody(resp, body)63 def update_image(self, image_id, data=None, headers=None):64 """Update an image.65 For a full list of available parameters, please refer to the official66 API reference:67 http://developer.openstack.org/api-ref-image-v1.html#updateImage-v168 """69 if headers is None:70 headers = {}71 if data is not None:72 return self._update_with_data(image_id, headers, data)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run tempest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful