Best Python code snippet using tempest_python
test_server_metadata.py
Source:test_server_metadata.py
...31 cls.server_id = server['id']32 def setUp(self):33 super(ServerMetadataTestJSON, self).setUp()34 meta = {'key1': 'value1', 'key2': 'value2'}35 resp, _ = self.client.set_server_metadata(self.server_id, meta)36 self.assertEqual(resp.status, 200)37 @attr(type='gate')38 def test_list_server_metadata(self):39 # All metadata key/value pairs for a server should be returned40 resp, resp_metadata = self.client.list_server_metadata(self.server_id)41 # Verify the expected metadata items are in the list42 self.assertEqual(200, resp.status)43 expected = {'key1': 'value1', 'key2': 'value2'}44 self.assertEqual(expected, resp_metadata)45 @attr(type='gate')46 def test_set_server_metadata(self):47 # The server's metadata should be replaced with the provided values48 # Create a new set of metadata for the server49 req_metadata = {'meta2': 'data2', 'meta3': 'data3'}50 resp, metadata = self.client.set_server_metadata(self.server_id,51 req_metadata)52 self.assertEqual(200, resp.status)53 # Verify the expected values are correct, and that the54 # previous values have been removed55 resp, resp_metadata = self.client.list_server_metadata(self.server_id)56 self.assertEqual(resp_metadata, req_metadata)57 @attr(type='gate')58 def test_server_create_metadata_key_too_long(self):59 # Attempt to start a server with a meta-data key that is > 25560 # characters61 # Try a few values62 for sz in [256, 257, 511, 1023]:63 key = "k" * sz64 meta = {key: 'data1'}...
test_server_metadata_negative.py
Source:test_server_metadata_negative.py
1# Copyright 2012 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 ServerMetadataNegativeTestJSON(base.BaseV2ComputeTest):20 @classmethod21 def setup_clients(cls):22 super(ServerMetadataNegativeTestJSON, cls).setup_clients()23 cls.client = cls.servers_client24 cls.quotas = cls.quotas_client25 @classmethod26 def resource_setup(cls):27 super(ServerMetadataNegativeTestJSON, cls).resource_setup()28 cls.tenant_id = cls.client.tenant_id29 server = cls.create_test_server(metadata={}, wait_until='ACTIVE')30 cls.server_id = server['id']31 @test.attr(type=['negative'])32 @test.idempotent_id('fe114a8f-3a57-4eff-9ee2-4e14628df049')33 def test_server_create_metadata_key_too_long(self):34 # Attempt to start a server with a meta-data key that is > 25535 # characters36 # Tryset_server_metadata_item a few values37 for sz in [256, 257, 511, 1023]:38 key = "k" * sz39 meta = {key: 'data1'}40 self.assertRaises((lib_exc.BadRequest, lib_exc.OverLimit),41 self.create_test_server,42 metadata=meta)43 # no teardown - all creates should fail44 @test.attr(type=['negative'])45 @test.idempotent_id('92431555-4d8b-467c-b95b-b17daa5e57ff')46 def test_create_server_metadata_blank_key(self):47 # Blank key should trigger an error.48 meta = {'': 'data1'}49 self.assertRaises(lib_exc.BadRequest,50 self.create_test_server,51 metadata=meta)52 @test.attr(type=['negative'])53 @test.idempotent_id('4d9cd7a3-2010-4b41-b8fe-3bbf0b169466')54 def test_server_metadata_non_existent_server(self):55 # GET on a non-existent server should not succeed56 non_existent_server_id = data_utils.rand_uuid()57 self.assertRaises(lib_exc.NotFound,58 self.client.show_server_metadata_item,59 non_existent_server_id,60 'test2')61 @test.attr(type=['negative'])62 @test.idempotent_id('f408e78e-3066-4097-9299-3b0182da812e')63 def test_list_server_metadata_non_existent_server(self):64 # List metadata on a non-existent server should not succeed65 non_existent_server_id = data_utils.rand_uuid()66 self.assertRaises(lib_exc.NotFound,67 self.client.list_server_metadata,68 non_existent_server_id)69 @test.attr(type=['negative'])70 @test.idempotent_id('0025fbd6-a4ba-4cde-b8c2-96805dcfdabc')71 def test_wrong_key_passed_in_body(self):72 # Raise BadRequest if key in uri does not match73 # the key passed in body.74 meta = {'testkey': 'testvalue'}75 self.assertRaises(lib_exc.BadRequest,76 self.client.set_server_metadata_item,77 self.server_id, 'key', meta)78 @test.attr(type=['negative'])79 @test.idempotent_id('0df38c2a-3d4e-4db5-98d8-d4d9fa843a12')80 def test_set_metadata_non_existent_server(self):81 # Set metadata on a non-existent server should not succeed82 non_existent_server_id = data_utils.rand_uuid()83 meta = {'meta1': 'data1'}84 self.assertRaises(lib_exc.NotFound,85 self.client.set_server_metadata,86 non_existent_server_id,87 meta)88 @test.attr(type=['negative'])89 @test.idempotent_id('904b13dc-0ef2-4e4c-91cd-3b4a0f2f49d8')90 def test_update_metadata_non_existent_server(self):91 # An update should not happen for a non-existent server92 non_existent_server_id = data_utils.rand_uuid()93 meta = {'key1': 'value1', 'key2': 'value2'}94 self.assertRaises(lib_exc.NotFound,95 self.client.update_server_metadata,96 non_existent_server_id,97 meta)98 @test.attr(type=['negative'])99 @test.idempotent_id('a452f38c-05c2-4b47-bd44-a4f0bf5a5e48')100 def test_update_metadata_with_blank_key(self):101 # Blank key should trigger an error102 meta = {'': 'data1'}103 self.assertRaises(lib_exc.BadRequest,104 self.client.update_server_metadata,105 self.server_id, meta=meta)106 @test.attr(type=['negative'])107 @test.idempotent_id('6bbd88e1-f8b3-424d-ba10-ae21c45ada8d')108 def test_delete_metadata_non_existent_server(self):109 # Should not be able to delete metadata item from a non-existent server110 non_existent_server_id = data_utils.rand_uuid()111 self.assertRaises(lib_exc.NotFound,112 self.client.delete_server_metadata_item,113 non_existent_server_id,114 'd')115 @test.attr(type=['negative'])116 @test.idempotent_id('d8c0a210-a5c3-4664-be04-69d96746b547')117 def test_metadata_items_limit(self):118 # A 403 Forbidden or 413 Overlimit (old behaviour) exception119 # will be raised while exceeding metadata items limit for120 # tenant.121 quota_set = self.quotas.show_quota_set(self.tenant_id)['quota_set']122 quota_metadata = quota_set['metadata_items']123 if quota_metadata == -1:124 raise self.skipException("No limit for metadata_items")125 req_metadata = {}126 for num in range(1, quota_metadata + 2):127 req_metadata['key' + str(num)] = 'val' + str(num)128 self.assertRaises((lib_exc.OverLimit, lib_exc.Forbidden),129 self.client.set_server_metadata,130 self.server_id, req_metadata)131 # A 403 Forbidden or 413 Overlimit (old behaviour) exception132 # will be raised while exceeding metadata items limit for133 # tenant.134 self.assertRaises((lib_exc.Forbidden, lib_exc.OverLimit),135 self.client.update_server_metadata,136 self.server_id, req_metadata)137 @test.attr(type=['negative'])138 @test.idempotent_id('96100343-7fa9-40d8-80fa-d29ef588ce1c')139 def test_set_server_metadata_blank_key(self):140 # Raise a bad request error for blank key.141 # set_server_metadata will replace all metadata with new value142 meta = {'': 'data1'}143 self.assertRaises(lib_exc.BadRequest,144 self.client.set_server_metadata,145 self.server_id, meta=meta)146 @test.attr(type=['negative'])147 @test.idempotent_id('64a91aee-9723-4863-be44-4c9d9f1e7d0e')148 def test_set_server_metadata_missing_metadata(self):149 # Raise a bad request error for a missing metadata field150 # set_server_metadata will replace all metadata with new value151 meta = {'meta1': 'data1'}152 self.assertRaises(lib_exc.BadRequest,153 self.client.set_server_metadata,...
test_server.py
Source:test_server.py
...62 # get metadata63 test_server = self.conn.compute.get_server_metadata(test_server)64 self.assertFalse(test_server.metadata)65 # set no metadata66 self.conn.compute.set_server_metadata(test_server)67 test_server = self.conn.compute.get_server_metadata(test_server)68 self.assertFalse(test_server.metadata)69 # set empty metadata70 self.conn.compute.set_server_metadata(test_server, k0='')71 server = self.conn.compute.get_server_metadata(test_server)72 self.assertTrue(server.metadata)73 # set metadata74 self.conn.compute.set_server_metadata(test_server, k1='v1')75 test_server = self.conn.compute.get_server_metadata(test_server)76 self.assertTrue(test_server.metadata)77 self.assertEqual(2, len(test_server.metadata))78 self.assertIn('k0', test_server.metadata)79 self.assertEqual('', test_server.metadata['k0'])80 self.assertIn('k1', test_server.metadata)81 self.assertEqual('v1', test_server.metadata['k1'])82 # set more metadata83 self.conn.compute.set_server_metadata(test_server, k2='v2')84 test_server = self.conn.compute.get_server_metadata(test_server)85 self.assertTrue(test_server.metadata)86 self.assertEqual(3, len(test_server.metadata))87 self.assertIn('k0', test_server.metadata)88 self.assertEqual('', test_server.metadata['k0'])89 self.assertIn('k1', test_server.metadata)90 self.assertEqual('v1', test_server.metadata['k1'])91 self.assertIn('k2', test_server.metadata)92 self.assertEqual('v2', test_server.metadata['k2'])93 # update metadata94 self.conn.compute.set_server_metadata(test_server, k1='v1.1')95 test_server = self.conn.compute.get_server_metadata(test_server)96 self.assertTrue(test_server.metadata)97 self.assertEqual(3, len(test_server.metadata))98 self.assertIn('k0', test_server.metadata)99 self.assertEqual('', test_server.metadata['k0'])100 self.assertIn('k1', test_server.metadata)101 self.assertEqual('v1.1', test_server.metadata['k1'])102 self.assertIn('k2', test_server.metadata)103 self.assertEqual('v2', test_server.metadata['k2'])104 # delete metadata105 self.conn.compute.delete_server_metadata(106 test_server, test_server.metadata.keys())107 test_server = self.conn.compute.get_server_metadata(test_server)108 self.assertFalse(test_server.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!!