Best Python code snippet using tempest_python
test_volumes_list.py
Source:test_volumes_list.py
...27 # If you are running a Devstack environment, ensure that the28 # VOLUME_BACKING_FILE_SIZE is at least 4G in your localrc29 VOLUME_FIELDS = ('id', 'name')30 @classmethod31 def _remove_volatile_fields(cls, fetched_list):32 """Remove fields that should not be compared.33 This method makes sure that Tempest does not compare e.g.34 the volume's "updated_at" field that may change for any reason35 internal to the operation of Cinder.36 """37 for volume in fetched_list:38 for field in ('updated_at',):39 if field in volume:40 del volume[field]41 def _assert_volumes_in(self, fetched_list, expected_list, fields=None):42 """Check out the list.43 This function is aim at check out whether all of the volumes in44 expected_list are in fetched_list.45 """46 if fields:47 fieldsgetter = operator.itemgetter(*fields)48 expected_list = map(fieldsgetter, expected_list)49 fetched_list = [fieldsgetter(item) for item in fetched_list]50 # Hopefully the expected_list has already been cleaned.51 self._remove_volatile_fields(fetched_list)52 missing_vols = [v for v in expected_list if v not in fetched_list]53 if not missing_vols:54 return55 def str_vol(vol):56 return "%s:%s" % (vol['id'], vol['name'])57 raw_msg = "Could not find volumes %s in expected list %s; fetched %s"58 self.fail(raw_msg % ([str_vol(v) for v in missing_vols],59 [str_vol(v) for v in expected_list],60 [str_vol(v) for v in fetched_list]))61 @classmethod62 def resource_setup(cls):63 super(VolumesListTestJSON, cls).resource_setup()64 existing_volumes = cls.volumes_client.list_volumes()['volumes']65 cls.volume_id_list = [vol['id'] for vol in existing_volumes]66 # Create 3 test volumes67 cls.volume_list = []68 cls.metadata = {'Type': 'work'}69 for _ in range(3):70 volume = cls.create_volume(metadata=cls.metadata)71 volume = cls.volumes_client.show_volume(volume['id'])['volume']72 cls.volume_list.append(volume)73 cls.volume_id_list.append(volume['id'])74 cls._remove_volatile_fields(cls.volume_list)75 def _list_by_param_value_and_assert(self, params, with_detail=False):76 """list or list_details with given params and validates result"""77 if with_detail:78 fetched_vol_list = \79 self.volumes_client.list_volumes(detail=True,80 params=params)['volumes']81 else:82 fetched_vol_list = self.volumes_client.list_volumes(83 params=params)['volumes']84 # Validating params of fetched volumes85 if with_detail:86 for volume in fetched_vol_list:87 for key in params:88 msg = "Failed to list volumes %s by %s" % \...
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!!