Best Python code snippet using tempest_python
test_object_expiry.py
Source:test_object_expiry.py
...32 @classmethod33 def resource_cleanup(cls):34 cls.delete_containers([cls.container_name])35 super(ObjectExpiryTest, cls).resource_cleanup()36 def _test_object_expiry(self, metadata):37 # update object metadata38 resp, _ = \39 self.object_client.update_object_metadata(self.container_name,40 self.object_name,41 metadata,42 metadata_prefix='')43 # verify object metadata44 resp, _ = \45 self.object_client.list_object_metadata(self.container_name,46 self.object_name)47 self.assertEqual(resp['status'], '200')48 self.assertHeaders(resp, 'Object', 'HEAD')49 self.assertIn('x-delete-at', resp)50 # we want to ensure that we will sleep long enough for things to51 # actually expire, so figure out how many secs in the future that is.52 sleepy_time = int(resp['x-delete-at']) - int(time.time())53 resp, body = self.object_client.get_object(self.container_name,54 self.object_name)55 self.assertEqual(resp['status'], '200')56 self.assertHeaders(resp, 'Object', 'GET')57 self.assertIn('x-delete-at', resp)58 # add a couple of seconds for safety.59 time.sleep(sleepy_time + 3)60 # object should not be there anymore61 self.assertRaises(exceptions.NotFound, self.object_client.get_object,62 self.container_name, self.object_name)63 @test.attr(type='gate')64 def test_get_object_after_expiry_time(self):65 # the 10s is important, because the get calls can take 3s each66 # some times67 metadata = {'X-Delete-After': '10'}68 self._test_object_expiry(metadata)69 @test.attr(type='gate')70 def test_get_object_at_expiry_time(self):71 metadata = {'X-Delete-At': str(int(time.time()) + 10)}...
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!!