Best Python code snippet using tempest_python
test_object_slo.py
Source:test_object_slo.py  
...66                         {'path': path_object_2,67                          'etag': hashlib.md5(self.content).hexdigest(),68                          'size_bytes': data_size}]69        return json.dumps(data_manifest)70    def _create_large_object(self):71        # Create a large object for preparation of testing various SLO72        # features73        manifest = self._create_manifest()74        params = {'multipart-manifest': 'put'}75        object_name = data_utils.rand_name(name='TestObject')76        self._create_object(self.container_name,77                            object_name,78                            manifest,79                            params)80        return object_name81    def _assertHeadersSLO(self, resp, method):82        # When sending GET or HEAD requests to SLO the response contains83        # 'X-Static-Large-Object' header84        if method in ('GET', 'HEAD'):85            self.assertIn('x-static-large-object', resp)86            self.assertEqual(resp['x-static-large-object'], 'True')87        # Etag value of a large object is enclosed in double-quotations.88        # After etag quotes are checked they are removed and the response is89        # checked if all common headers are present and well formatted90        self.assertTrue(resp['etag'].startswith('\"'))91        self.assertTrue(resp['etag'].endswith('\"'))92        resp['etag'] = resp['etag'].strip('"')93        self.assertHeaders(resp, 'Object', method)94    @test.idempotent_id('2c3f24a6-36e8-4711-9aa2-800ee1fc7b5b')95    @test.requires_ext(extension='slo', service='object')96    def test_upload_manifest(self):97        # create static large object from multipart manifest98        manifest = self._create_manifest()99        params = {'multipart-manifest': 'put'}100        object_name = data_utils.rand_name(name='TestObject')101        resp = self._create_object(self.container_name,102                                   object_name,103                                   manifest,104                                   params)105        self._assertHeadersSLO(resp, 'PUT')106    @test.idempotent_id('e69ad766-e1aa-44a2-bdd2-bf62c09c1456')107    @test.requires_ext(extension='slo', service='object')108    def test_list_large_object_metadata(self):109        # list static large object metadata using multipart manifest110        object_name = self._create_large_object()111        resp, body = self.object_client.list_object_metadata(112            self.container_name,113            object_name)114        self._assertHeadersSLO(resp, 'HEAD')115    @test.idempotent_id('49bc49bc-dd1b-4c0f-904e-d9f10b830ee8')116    @test.requires_ext(extension='slo', service='object')117    def test_retrieve_large_object(self):118        # list static large object using multipart manifest119        object_name = self._create_large_object()120        resp, body = self.object_client.get_object(121            self.container_name,122            object_name)123        self._assertHeadersSLO(resp, 'GET')124        sum_data = self.content + self.content125        self.assertEqual(body, sum_data)126    @test.idempotent_id('87b6dfa1-abe9-404d-8bf0-6c3751e6aa77')127    @test.requires_ext(extension='slo', service='object')128    def test_delete_large_object(self):129        # delete static large object using multipart manifest130        object_name = self._create_large_object()131        params_del = {'multipart-manifest': 'delete'}132        resp, body = self.object_client.delete_object(133            self.container_name,134            object_name,135            params=params_del)136        # When deleting SLO using multipart manifest, the response contains137        # not 'content-length' but 'transfer-encoding' header. This is the138        # special case, therefore the existence of response headers is checked139        # outside of custom matcher.140        self.assertIn('transfer-encoding', resp)141        self.assertIn('content-type', resp)142        self.assertIn('x-trans-id', resp)143        self.assertIn('date', resp)144        # Check only the format of common headers with custom matcher...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
