Best Python code snippet using tempest_python
images_client.py
Source:images_client.py
...70 resp, body = self.post('images/%s/metadata' % image_id, post_body)71 body = json.loads(body)72 self.validate_response(schema.image_metadata, resp, body)73 return service_client.ResponseBody(resp, body['metadata'])74 def show_image_metadata_item(self, image_id, key):75 """Returns the value for a specific image metadata key."""76 resp, body = self.get("images/%s/metadata/%s" % (image_id, key))77 body = json.loads(body)78 self.validate_response(schema.image_meta_item, resp, body)79 return service_client.ResponseBody(resp, body['meta'])80 def set_image_metadata_item(self, image_id, key, meta):81 """Sets the value for a specific image metadata key."""82 post_body = json.dumps({'meta': meta})83 resp, body = self.put('images/%s/metadata/%s' % (image_id, key),84 post_body)85 body = json.loads(body)86 self.validate_response(schema.image_meta_item, resp, body)87 return service_client.ResponseBody(resp, body['meta'])88 def delete_image_metadata_item(self, image_id, key):...
test_image_metadata_negative.py
Source:test_image_metadata_negative.py
1# Copyright 2013 OpenStack Foundation2# All Rights Reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License"); you may5# not use this file except in compliance with the License. You may obtain6# a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13# License for the specific language governing permissions and limitations14# under the License.15from tempest_lib import exceptions as lib_exc16from tempest.api.compute import base17from tempest.common.utils import data_utils18from tempest import test19class ImagesMetadataTestJSON(base.BaseV2ComputeTest):20 @classmethod21 def setup_clients(cls):22 super(ImagesMetadataTestJSON, cls).setup_clients()23 cls.client = cls.compute_images_client24 @test.attr(type=['negative'])25 @test.idempotent_id('94069db2-792f-4fa8-8bd3-2271a6e0c095')26 def test_list_nonexistent_image_metadata(self):27 # Negative test: List on nonexistent image28 # metadata should not happen29 self.assertRaises(lib_exc.NotFound, self.client.list_image_metadata,30 data_utils.rand_uuid())31 @test.attr(type=['negative'])32 @test.idempotent_id('a403ef9e-9f95-427c-b70a-3ce3388796f1')33 def test_update_nonexistent_image_metadata(self):34 # Negative test:An update should not happen for a non-existent image35 meta = {'os_distro': 'alt1', 'os_version': 'alt2'}36 self.assertRaises(lib_exc.NotFound,37 self.client.update_image_metadata,38 data_utils.rand_uuid(), meta)39 @test.attr(type=['negative'])40 @test.idempotent_id('41ae052c-6ee6-405c-985e-5712393a620d')41 def test_get_nonexistent_image_metadata_item(self):42 # Negative test: Get on non-existent image should not happen43 self.assertRaises(lib_exc.NotFound,44 self.client.show_image_metadata_item,45 data_utils.rand_uuid(), 'os_version')46 @test.attr(type=['negative'])47 @test.idempotent_id('dc64f2ce-77e8-45b0-88c8-e15041d08eaf')48 def test_set_nonexistent_image_metadata(self):49 # Negative test: Metadata should not be set to a non-existent image50 meta = {'os_distro': 'alt1', 'os_version': 'alt2'}51 self.assertRaises(lib_exc.NotFound, self.client.set_image_metadata,52 data_utils.rand_uuid(), meta)53 @test.attr(type=['negative'])54 @test.idempotent_id('2154fd03-ab54-457c-8874-e6e3eb56e9cf')55 def test_set_nonexistent_image_metadata_item(self):56 # Negative test: Metadata item should not be set to a57 # nonexistent image58 meta = {'os_distro': 'alt'}59 self.assertRaises(lib_exc.NotFound,60 self.client.set_image_metadata_item,61 data_utils.rand_uuid(), 'os_distro',62 meta)63 @test.attr(type=['negative'])64 @test.idempotent_id('848e157f-6bcf-4b2e-a5dd-5124025a8518')65 def test_delete_nonexistent_image_metadata_item(self):66 # Negative test: Shouldn't be able to delete metadata67 # item from non-existent image68 self.assertRaises(lib_exc.NotFound,69 self.client.delete_image_metadata_item,...
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!!