Best Python code snippet using tempest_python
test_images_client.py
Source:test_images_client.py  
...96        super(TestImagesClient, self).setUp()97        fake_auth = fake_auth_provider.FakeAuthProvider()98        self.client = images_client.ImagesClient(fake_auth,99                                                 "compute", "regionOne")100    def _test_image_operation(self, operation="delete", bytes_body=False):101        response_code = 200102        mock_operation = self.func2mock['get']103        expected_op = self.FAKE_IMAGE_DATA[operation]104        params = {"image_id": self.FAKE_IMAGE_ID}105        headers = None106        if operation == 'list':107            function = self.client.list_images108        elif operation == 'show':109            function = self.client.show_image110        elif operation == 'create':111            function = self.client.create_image112            mock_operation = self.func2mock['post']113            params = {"server_id": self.FAKE_SERVER_ID}114            response_code = 202115            headers = {116                'connection': 'keep-alive',117                'content-length': '0',118                'content-type': 'application/json',119                'status': '202',120                'x-compute-request-id': 'req-fake',121                'vary': 'accept-encoding',122                'x-openstack-nova-api-version': 'v2.1',123                'date': '13 Oct 2015 05:55:36 GMT',124                'location': 'http://fake.com/images/fake'125            }126        else:127            function = self.client.delete_image128            mock_operation = self.func2mock['delete']129            response_code = 204130        self.check_service_client_function(131            function, mock_operation, expected_op,132            bytes_body, response_code, headers, **params)133    def _test_image_metadata(self, operation="set_item", bytes_body=False):134        response_code = 200135        expected_op = self.FAKE_IMAGE_METADATA[operation]136        if operation == 'list':137            function = self.client.list_image_metadata138            mock_operation = self.func2mock['get']139            params = {"image_id": self.FAKE_IMAGE_ID}140        elif operation == 'set':141            function = self.client.set_image_metadata142            mock_operation = self.func2mock['put']143            params = {"image_id": "_dummy_data",144                      "meta": self.FAKE_METADATA}145        elif operation == 'update':146            function = self.client.update_image_metadata147            mock_operation = self.func2mock['post']148            params = {"image_id": self.FAKE_IMAGE_ID,149                      "meta": self.FAKE_METADATA}150        elif operation == 'show_item':151            mock_operation = self.func2mock['get']152            function = self.client.show_image_metadata_item153            params = {"image_id": self.FAKE_IMAGE_ID,154                      "key": "123"}155        elif operation == 'delete_item':156            function = self.client.delete_image_metadata_item157            mock_operation = self.func2mock['delete']158            response_code = 204159            params = {"image_id": self.FAKE_IMAGE_ID,160                      "key": "123"}161        else:162            function = self.client.set_image_metadata_item163            mock_operation = self.func2mock['put']164            params = {"image_id": self.FAKE_IMAGE_ID,165                      "key": "123",166                      "meta": self.FAKE_METADATA}167        self.check_service_client_function(168            function, mock_operation, expected_op,169            bytes_body, response_code, **params)170    def _test_resource_deleted(self, bytes_body=False):171        params = {"id": self.FAKE_IMAGE_ID}172        expected_op = self.FAKE_IMAGE_DATA['show']173        self.useFixture(174            fixtures.MockPatch(175                'tempest.lib.services.compute'176                '.images_client.ImagesClient.show_image',177                side_effect=lib_exc.NotFound))178        self.assertEqual(True, self.client.is_resource_deleted(**params))179        tempdata = copy.deepcopy(self.FAKE_IMAGE_DATA['show'])180        tempdata['image']['id'] = None181        self.useFixture(182            fixtures.MockPatch(183                'tempest.lib.services.compute'184                '.images_client.ImagesClient.show_image',185                return_value=expected_op))186        self.assertEqual(False, self.client.is_resource_deleted(**params))187    def test_list_images_with_str_body(self):188        self._test_image_operation('list')189    def test_list_images_with_bytes_body(self):190        self._test_image_operation('list', True)191    def test_show_image_with_str_body(self):192        self._test_image_operation('show')193    def test_show_image_with_bytes_body(self):194        self._test_image_operation('show', True)195    def test_create_image_with_str_body(self):196        self._test_image_operation('create')197    def test_create_image_with_bytes_body(self):198        self._test_image_operation('create', True)199    def test_delete_image_with_str_body(self):200        self._test_image_operation('delete')201    def test_delete_image_with_bytes_body(self):202        self._test_image_operation('delete', True)203    def test_list_image_metadata_with_str_body(self):204        self._test_image_metadata('list')205    def test_list_image_metadata_with_bytes_body(self):206        self._test_image_metadata('list', True)207    def test_set_image_metadata_with_str_body(self):208        self._test_image_metadata('set')209    def test_set_image_metadata_with_bytes_body(self):210        self._test_image_metadata('set', True)211    def test_update_image_metadata_with_str_body(self):212        self._test_image_metadata('update')213    def test_update_image_metadata_with_bytes_body(self):214        self._test_image_metadata('update', True)215    def test_set_image_metadata_item_with_str_body(self):216        self._test_image_metadata()...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!!
