How to use list_container_objects method in tempest

Best Python code snippet using tempest_python

test_container_services.py

Source:test_container_services.py Github

copy

Full Screen

...107 def test_list_container_contents(self):108 # get container contents list109 container_name = self.create_container()110 object_name, _ = self.create_object(container_name)111 resp, object_list = self.container_client.list_container_objects(112 container_name)113 self.assertHeaders(resp, 'Container', 'GET')114 self.assertEqual([object_name], object_list)115 @decorators.idempotent_id('4646ac2d-9bfb-4c7d-a3c5-0f527402b3df')116 def test_list_container_contents_with_no_object(self):117 # get empty container contents list118 container_name = self.create_container()119 resp, object_list = self.container_client.list_container_objects(120 container_name)121 self.assertHeaders(resp, 'Container', 'GET')122 self.assertEmpty(object_list)123 @decorators.idempotent_id('fe323a32-57b9-4704-a996-2e68f83b09bc')124 def test_list_container_contents_with_delimiter(self):125 # get container contents list using delimiter param126 container_name = self.create_container()127 object_name = data_utils.rand_name(name='TestObject/')128 self.create_object(container_name, object_name)129 params = {'delimiter': '/'}130 resp, object_list = self.container_client.list_container_objects(131 container_name,132 params=params)133 self.assertHeaders(resp, 'Container', 'GET')134 self.assertEqual([object_name.split('/')[0] + '/'], object_list)135 @decorators.idempotent_id('55b4fa5c-e12e-4ca9-8fcf-a79afe118522')136 def test_list_container_contents_with_end_marker(self):137 # get container contents list using end_marker param138 container_name = self.create_container()139 object_name, _ = self.create_object(container_name)140 params = {'end_marker': object_name + 'zzzz'}141 resp, object_list = self.container_client.list_container_objects(142 container_name,143 params=params)144 self.assertHeaders(resp, 'Container', 'GET')145 self.assertEqual([object_name], object_list)146 @decorators.idempotent_id('196f5034-6ab0-4032-9da9-a937bbb9fba9')147 def test_list_container_contents_with_format_json(self):148 # get container contents list using format_json param149 container_name = self.create_container()150 self.create_object(container_name)151 params = {'format': 'json'}152 resp, object_list = self.container_client.list_container_objects(153 container_name,154 params=params)155 self.assertHeaders(resp, 'Container', 'GET')156 self.assertIsNotNone(object_list)157 self.assertTrue([c['name'] for c in object_list])158 self.assertTrue([c['hash'] for c in object_list])159 self.assertTrue([c['bytes'] for c in object_list])160 self.assertTrue([c['content_type'] for c in object_list])161 self.assertTrue([c['last_modified'] for c in object_list])162 @decorators.idempotent_id('655a53ca-4d15-408c-a377-f4c6dbd0a1fa')163 def test_list_container_contents_with_format_xml(self):164 # get container contents list using format_xml param165 container_name = self.create_container()166 self.create_object(container_name)167 params = {'format': 'xml'}168 resp, object_list = self.container_client.list_container_objects(169 container_name,170 params=params)171 self.assertHeaders(resp, 'Container', 'GET')172 self.assertIsNotNone(object_list)173 self.assertEqual(object_list.tag, 'container')174 self.assertIn('name', object_list.keys())175 self.assertEqual(object_list.find(".//object").tag, 'object')176 self.assertEqual(object_list.find(".//name").tag, 'name')177 self.assertEqual(object_list.find(".//hash").tag, 'hash')178 self.assertEqual(object_list.find(".//bytes").tag, 'bytes')179 self.assertEqual(object_list.find(".//content_type").tag,180 'content_type')181 self.assertEqual(object_list.find(".//last_modified").tag,182 'last_modified')183 @decorators.idempotent_id('297ec38b-2b61-4ff4-bcd1-7fa055e97b61')184 def test_list_container_contents_with_limit(self):185 # get container contents list using limit param186 container_name = self.create_container()187 object_name, _ = self.create_object(container_name)188 params = {'limit': data_utils.rand_int_id(1, 10000)}189 resp, object_list = self.container_client.list_container_objects(190 container_name,191 params=params)192 self.assertHeaders(resp, 'Container', 'GET')193 self.assertEqual([object_name], object_list)194 @decorators.idempotent_id('c31ddc63-2a58-4f6b-b25c-94d2937e6867')195 def test_list_container_contents_with_marker(self):196 # get container contents list using marker param197 container_name = self.create_container()198 object_name, _ = self.create_object(container_name)199 params = {'marker': 'AaaaObject1234567890'}200 resp, object_list = self.container_client.list_container_objects(201 container_name,202 params=params)203 self.assertHeaders(resp, 'Container', 'GET')204 self.assertEqual([object_name], object_list)205 @decorators.idempotent_id('58ca6cc9-6af0-408d-aaec-2a6a7b2f0df9')206 def test_list_container_contents_with_path(self):207 # get container contents list using path param208 container_name = self.create_container()209 object_name = data_utils.rand_name(name='TestObject')210 object_name = 'Swift/' + object_name211 self.create_object(container_name, object_name)212 params = {'path': 'Swift'}213 resp, object_list = self.container_client.list_container_objects(214 container_name,215 params=params)216 self.assertHeaders(resp, 'Container', 'GET')217 self.assertEqual([object_name], object_list)218 @decorators.idempotent_id('77e742c7-caf2-4ec9-8aa4-f7d509a3344c')219 def test_list_container_contents_with_prefix(self):220 # get container contents list using prefix param221 container_name = self.create_container()222 object_name, _ = self.create_object(container_name)223 prefix_key = object_name[0:8]224 params = {'prefix': prefix_key}225 resp, object_list = self.container_client.list_container_objects(226 container_name,227 params=params)228 self.assertHeaders(resp, 'Container', 'GET')229 self.assertEqual([object_name], object_list)230 @decorators.attr(type='smoke')231 @decorators.idempotent_id('96e68f0e-19ec-4aa2-86f3-adc6a45e14dd')232 def test_list_container_metadata(self):233 # List container metadata234 container_name = self.create_container()235 metadata = {'name': 'Pictures'}236 self.container_client.create_update_or_delete_container_metadata(237 container_name,238 create_update_metadata=metadata)239 resp, _ = self.container_client.list_container_metadata(...

Full Screen

Full Screen

Provider.py

Source:Provider.py Github

copy

Full Screen

...56 else:57 print('Directory already present')58 #function to delete a directory59 def deleteDir(self, dirName):60 objects = self.s3Resource.list_container_objects(self.container)61 dirFilesList = []62 for objs in objects:63 if objs.name.startswith(self.trimFileNamePath(dirName)):64 self.s3Resource.delete_object(obj=objs)65 dirFilesList.append(objs.name)66 if len(dirFilesList) == 0:67 print("Directory not found")68 else:69 print('Directory deleted')70# function to delete a file71 def deleteFile(self, fileName, dirName):72 HEADING()73 filePath = self.joinFileNameDir(fileName, dirName)74 try:75 objs = self.s3Resource.get_object(self.container_name, filePath)76 except ObjectDoesNotExistError:77 print("File does not exist")78 else:79 delete_file_object = self.s3Resource.get_object(container_name=self.container_name, object_name=filePath)80 self.s3Resource.delete_object(obj=delete_file_object)81 print('File deleted')82 # function to upload a file to cloud from local storage83 def putFile(self, sourceFilename, sourceDir, destFilename, destDir):84 HEADING()85 sourceFilePath = self.joinFileNameDir(sourceFilename,sourceDir)86 targetFilePath = self.joinFileNameDir(destFilename,destDir)87 self.s3Resource.upload_object(sourceFilePath, self.container, targetFilePath, extra=None, verify_hash=True)88 print('File uploaded')89 # function to download a file from a cloud to local storage90 def getFile(self, sourceFilename, sourceDir, destFilename, destDir):91 HEADING()92 sourceFilePath = self.joinFileNameDir(sourceFilename,sourceDir)93 targetFilePath = self.joinFileNameDir(destFilename,destDir)94 file_object = self.s3Resource.get_object(container_name=self.container_name, object_name=sourceFilePath)95 self.s3Resource.download_object(file_object, targetFilePath, overwrite_existing=True, delete_on_failure=True)96 print('File downloaded')97# function to list files in a directory98 def listDirFiles(self, dirName):99 objects = self.s3Resource.list_container_objects(self.container)100 dirFilesList = []101 for objs in objects:102 if objs.name.startswith(self.trimFileNamePath(dirName)):103 #print("File found in directory")104 print(objs.name)105 dirFilesList.append(objs.name)106 if len(dirFilesList) == 0:107 print("No files found in directory")108# function to search a file109 def searchFile(self, fileName, dirName):110 HEADING()111 filePath = self.joinFileNameDir(fileName, dirName)112 dirFilesList = []113 try:114 if (len(dirName)>0):115 objs = self.s3Resource.get_object(self.container_name, filePath)116 print(objs.name)117 else:118 objs = self.s3Resource.list_container_objects(self.container)119 for obj in objs:120 if self.splitToList(obj.name)[-1] == fileName:121 print(obj.name)122 dirFilesList.append(obj.name)123 if len(dirFilesList) == 0:124 print("File does not exist")125 except ObjectDoesNotExistError:126 print("File does not exist")127# function to list file info128 def listFileInfo(self, fileName, dirName):129 HEADING()130 filePath = self.joinFileNameDir(fileName, dirName)131 dirFilesList = []132 infoList = []133 try:134 if (len(dirName) > 0):135 objs = self.s3Resource.get_object(self.container_name, filePath)136 print(objs.name)137 info = {138 "fileName": objs.name,139 "hash": objs.hash,140 "contentLength": objs.size141 }142 infoList.append(info)143 else:144 objs = self.s3Resource.list_container_objects(self.container)145 for obj in objs:146 if self.splitToList(obj.name)[-1] == fileName:147 info = {148 "fileName": obj.name,149 "hash": obj.hash,150 "contentLength": obj.size151 }152 dirFilesList.append(obj.name)153 infoList.append(info)154 if len(dirFilesList) == 0:155 print("File does not exist")156 except ObjectDoesNotExistError:157 print("File does not exist")158 pprint(infoList)...

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