How to use _list_sorted_by_image_size_and_assert method in tempest

Best Python code snippet using tempest_python

test_images.py

Source:test_images.py Github

copy

Full Screen

...149 for image in images_list:150 for key in params:151 msg = "Failed to list images by %s" % key152 self.assertEqual(params[key], image[key], msg)153 def _list_sorted_by_image_size_and_assert(self, params, desc=False):154 """Validate an image list that has been sorted by size155 Perform list action with given params and validates the results are156 sorted by image size in either ascending or descending order.157 """158 # Retrieve the list of images that meet the filter159 images_list = self.client.list_images(params=params)['images']160 # Validate that the list was fetched sorted accordingly161 msg = 'No images were found that met the filter criteria.'162 self.assertNotEmpty(images_list, msg)163 sorted_list = [image['size'] for image in images_list]164 msg = 'The list of images was not sorted correctly.'165 self.assertEqual(sorted(sorted_list, reverse=desc), sorted_list, msg)166 @decorators.idempotent_id('1e341d7a-90a9-494c-b143-2cdf2aeb6aee')167 def test_list_no_params(self):168 # Simple test to see all fixture images returned169 images_list = self.client.list_images()['images']170 image_list = [image['id'] for image in images_list]171 for image in self.created_images:172 self.assertIn(image, image_list)173 @decorators.idempotent_id('9959ca1d-1aa7-4b7a-a1ea-0fff0499b37e')174 def test_list_images_param_container_format(self):175 # Test to get all images with a specific container_format176 params = {"container_format": self.test_data['container_format']}177 self._list_by_param_value_and_assert(params)178 @decorators.idempotent_id('4a4735a7-f22f-49b6-b0d9-66e1ef7453eb')179 def test_list_images_param_disk_format(self):180 # Test to get all images with disk_format = raw181 params = {"disk_format": "raw"}182 self._list_by_param_value_and_assert(params)183 @decorators.idempotent_id('7a95bb92-d99e-4b12-9718-7bc6ab73e6d2')184 def test_list_images_param_visibility(self):185 # Test to get all images with visibility = private186 params = {"visibility": "private"}187 self._list_by_param_value_and_assert(params)188 @decorators.idempotent_id('cf1b9a48-8340-480e-af7b-fe7e17690876')189 def test_list_images_param_size(self):190 # Test to get all images by size191 image_id = self.created_images[0]192 # Get image metadata193 image = self.client.show_image(image_id)194 params = {"size": image['size']}195 self._list_by_param_value_and_assert(params)196 @decorators.idempotent_id('4ad8c157-971a-4ba8-aa84-ed61154b1e7f')197 def test_list_images_param_min_max_size(self):198 # Test to get all images with size between 2000 to 3000199 image_id = self.created_images[0]200 # Get image metadata201 image = self.client.show_image(image_id)202 size = image['size']203 params = {"size_min": size - 500, "size_max": size + 500}204 images_list = self.client.list_images(params=params)['images']205 image_size_list = map(lambda x: x['size'], images_list)206 for image_size in image_size_list:207 self.assertGreaterEqual(image_size, params['size_min'],208 "Failed to get images by size_min")209 self.assertLessEqual(image_size, params['size_max'],210 "Failed to get images by size_max")211 @decorators.idempotent_id('7fc9e369-0f58-4d05-9aa5-0969e2d59d15')212 def test_list_images_param_status(self):213 # Test to get all active images214 params = {"status": "active"}215 self._list_by_param_value_and_assert(params)216 @decorators.idempotent_id('e914a891-3cc8-4b40-ad32-e0a39ffbddbb')217 def test_list_images_param_limit(self):218 # Test to get images by limit219 params = {"limit": 1}220 images_list = self.client.list_images(params=params)['images']221 self.assertEqual(len(images_list), params['limit'],222 "Failed to get images by limit")223 @decorators.idempotent_id('e9a44b91-31c8-4b40-a332-e0a39ffb4dbb')224 def test_list_image_param_owner(self):225 # Test to get images by owner226 image_id = self.created_images[0]227 # Get image metadata228 image = self.client.show_image(image_id)229 params = {"owner": image['owner']}230 self._list_by_param_value_and_assert(params)231 @decorators.idempotent_id('55c8f5f5-bfed-409d-a6d5-4caeda985d7b')232 def test_list_images_param_name(self):233 # Test to get images by name234 params = {'name': self.test_data['name']}235 self._list_by_param_value_and_assert(params)236 @decorators.idempotent_id('aa8ac4df-cff9-418b-8d0f-dd9c67b072c9')237 def test_list_images_param_tag(self):238 # Test to get images matching a tag239 params = {'tag': self.test_data['tags'][0]}240 images_list = self.client.list_images(params=params)['images']241 # Validating properties of fetched images242 self.assertNotEmpty(images_list)243 for image in images_list:244 msg = ("The image {image_name} does not have the expected tag "245 "{expected_tag} among its tags: {observerd_tags}."246 .format(image_name=image['name'],247 expected_tag=self.test_data['tags'][0],248 observerd_tags=image['tags']))249 self.assertIn(self.test_data['tags'][0], image['tags'], msg)250 @decorators.idempotent_id('eeadce49-04e0-43b7-aec7-52535d903e7a')251 def test_list_images_param_sort(self):252 params = {'sort': 'size:desc'}253 self._list_sorted_by_image_size_and_assert(params, desc=True)254 @decorators.idempotent_id('9faaa0c2-c3a5-43e1-8f61-61c54b409a49')255 def test_list_images_param_sort_key_dir(self):256 params = {'sort_key': 'size', 'sort_dir': 'desc'}257 self._list_sorted_by_image_size_and_assert(params, desc=True)258 @decorators.idempotent_id('622b925c-479f-4736-860d-adeaf13bc371')259 def test_get_image_schema(self):260 # Test to get image schema261 schema = "image"262 body = self.schemas_client.show_schema(schema)263 self.assertEqual("image", body['name'])264 @decorators.idempotent_id('25c8d7b2-df21-460f-87ac-93130bcdc684')265 def test_get_images_schema(self):266 # Test to get images schema267 schema = "images"268 body = self.schemas_client.show_schema(schema)269 self.assertEqual("images", body['name'])270class ListSharedImagesTest(base.BaseV2ImageTest):271 """Here we test the listing of a shared image information"""...

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