How to use _list_by_param_value_and_assert method in tempest

Best Python code snippet using tempest_python

test_volumes_list.py

Source:test_volumes_list.py Github

copy

Full Screen

...61 for volid in cls.volume_id_list:62 cls.client.delete_volume(volid)63 cls.client.wait_for_resource_deletion(volid)64 super(VolumesV2ListTestJSON, cls).resource_cleanup()65 def _list_by_param_value_and_assert(self, params, with_detail=False):66 """list or list_details with given params and validates result"""67 if with_detail:68 fetched_vol_list = \69 self.client.list_volumes(detail=True, params=params)['volumes']70 else:71 fetched_vol_list = self.client.list_volumes(72 params=params)['volumes']73 # Validating params of fetched volumes74 # In v2, only list detail view includes items in params.75 # In v1, list view and list detail view are same. So the76 # following check should be run when 'with_detail' is True77 # or v1 tests.78 if with_detail or self._api_version == 1:79 for volume in fetched_vol_list:80 for key in params:81 msg = "Failed to list volumes %s by %s" % \82 ('details' if with_detail else '', key)83 if key == 'metadata':84 self.assertThat(85 volume[key].items(),86 matchers.ContainsAll(params[key].items()),87 msg)88 else:89 self.assertEqual(params[key], volume[key], msg)90 @test.attr(type='smoke')91 @test.idempotent_id('0b6ddd39-b948-471f-8038-4787978747c4')92 def test_volume_list(self):93 # Get a list of Volumes94 # Fetch all volumes95 fetched_list = self.client.list_volumes()['volumes']96 self.assertVolumesIn(fetched_list, self.volume_list,97 fields=self.VOLUME_FIELDS)98 @test.idempotent_id('adcbb5a7-5ad8-4b61-bd10-5380e111a877')99 def test_volume_list_with_details(self):100 # Get a list of Volumes with details101 # Fetch all Volumes102 fetched_list = self.client.list_volumes(detail=True)['volumes']103 self.assertVolumesIn(fetched_list, self.volume_list)104 @test.idempotent_id('a28e8da4-0b56-472f-87a8-0f4d3f819c02')105 def test_volume_list_by_name(self):106 volume = self.volume_list[data_utils.rand_int_id(0, 2)]107 params = {self.name: volume[self.name]}108 fetched_vol = self.client.list_volumes(params=params)['volumes']109 self.assertEqual(1, len(fetched_vol), str(fetched_vol))110 self.assertEqual(fetched_vol[0][self.name],111 volume[self.name])112 @test.idempotent_id('2de3a6d4-12aa-403b-a8f2-fdeb42a89623')113 def test_volume_list_details_by_name(self):114 volume = self.volume_list[data_utils.rand_int_id(0, 2)]115 params = {self.name: volume[self.name]}116 fetched_vol = self.client.list_volumes(117 detail=True, params=params)['volumes']118 self.assertEqual(1, len(fetched_vol), str(fetched_vol))119 self.assertEqual(fetched_vol[0][self.name],120 volume[self.name])121 @test.idempotent_id('39654e13-734c-4dab-95ce-7613bf8407ce')122 def test_volumes_list_by_status(self):123 params = {'status': 'available'}124 fetched_list = self.client.list_volumes(params=params)['volumes']125 self._list_by_param_value_and_assert(params)126 self.assertVolumesIn(fetched_list, self.volume_list,127 fields=self.VOLUME_FIELDS)128 @test.idempotent_id('2943f712-71ec-482a-bf49-d5ca06216b9f')129 def test_volumes_list_details_by_status(self):130 params = {'status': 'available'}131 fetched_list = self.client.list_volumes(132 detail=True, params=params)['volumes']133 for volume in fetched_list:134 self.assertEqual('available', volume['status'])135 self.assertVolumesIn(fetched_list, self.volume_list)136 @test.idempotent_id('c0cfa863-3020-40d7-b587-e35f597d5d87')137 def test_volumes_list_by_availability_zone(self):138 volume = self.volume_list[data_utils.rand_int_id(0, 2)]139 zone = volume['availability_zone']140 params = {'availability_zone': zone}141 fetched_list = self.client.list_volumes(params=params)['volumes']142 self._list_by_param_value_and_assert(params)143 self.assertVolumesIn(fetched_list, self.volume_list,144 fields=self.VOLUME_FIELDS)145 @test.idempotent_id('e1b80d13-94f0-4ba2-a40e-386af29f8db1')146 def test_volumes_list_details_by_availability_zone(self):147 volume = self.volume_list[data_utils.rand_int_id(0, 2)]148 zone = volume['availability_zone']149 params = {'availability_zone': zone}150 fetched_list = self.client.list_volumes(151 detail=True, params=params)['volumes']152 for volume in fetched_list:153 self.assertEqual(zone, volume['availability_zone'])154 self.assertVolumesIn(fetched_list, self.volume_list)155 @test.idempotent_id('b5ebea1b-0603-40a0-bb41-15fcd0a53214')156 def test_volume_list_with_param_metadata(self):157 # Test to list volumes when metadata param is given158 params = {'metadata': self.metadata}159 self._list_by_param_value_and_assert(params)160 @test.idempotent_id('1ca92d3c-4a8e-4b43-93f5-e4c7fb3b291d')161 def test_volume_list_with_detail_param_metadata(self):162 # Test to list volumes details when metadata param is given163 params = {'metadata': self.metadata}164 self._list_by_param_value_and_assert(params, with_detail=True)165 @test.idempotent_id('777c87c1-2fc4-4883-8b8e-5c0b951d1ec8')166 def test_volume_list_param_display_name_and_status(self):167 # Test to list volume when display name and status param is given168 volume = self.volume_list[data_utils.rand_int_id(0, 2)]169 params = {self.name: volume[self.name],170 'status': 'available'}171 self._list_by_param_value_and_assert(params)172 @test.idempotent_id('856ab8ca-6009-4c37-b691-be1065528ad4')173 def test_volume_list_with_detail_param_display_name_and_status(self):174 # Test to list volume when name and status param is given175 volume = self.volume_list[data_utils.rand_int_id(0, 2)]176 params = {self.name: volume[self.name],177 'status': 'available'}178 self._list_by_param_value_and_assert(params, with_detail=True)179class VolumesV1ListTestJSON(VolumesV2ListTestJSON):180 _api_version = 1...

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