Best Python code snippet using tempest_python
test_images_negative.py
Source:test_images_negative.py
...38 non_existent_image_id = '11a22b9-12a9-5555-cc11-00ab112223fa'39 self.assertRaises(exceptions.NotFound, self.client.delete_image,40 non_existent_image_id)41 @attr(type=['negative', 'gate'])42 def test_delete_image_blank_id(self):43 # Return an error while trying to delete an image with blank Id44 self.assertRaises(exceptions.NotFound, self.client.delete_image, '')45 @attr(type=['negative', 'gate'])46 def test_delete_image_non_hex_string_id(self):47 # Return an error while trying to delete an image with non hex id48 image_id = '11a22b9-120q-5555-cc11-00ab112223gj'49 self.assertRaises(exceptions.NotFound, self.client.delete_image,50 image_id)51 @attr(type=['negative', 'gate'])52 def test_delete_image_negative_image_id(self):53 # Return an error while trying to delete an image with negative id54 self.assertRaises(exceptions.NotFound, self.client.delete_image, -1)55 @attr(type=['negative', 'gate'])56 def test_delete_image_id_is_over_35_character_limit(self):...
openstack.py
Source:openstack.py
1from oslo.config import cfg2import requests3opts = [4 cfg.StrOpt('baremetal_endpoint', default='http://127.0.0.1:6385'),5 cfg.StrOpt('compute_endpoint', default='http://127.0.0.1:8774'),6 cfg.StrOpt('identity_endpoint', default='http://127.0.0.1:5000'),7 cfg.StrOpt('image_endpoint', default='http://127.0.0.1:9292'),8 cfg.StrOpt('network_endpoint', default='http://127.0.0.1:9696'),9 cfg.StrOpt('volume_endpoint', default='http://127.0.0.1:8776'),10]11cfg.CONF.register_opts(opts, group='openstack')12def setup_responder(app, disp, service):13 endpoint = app.config['openstack'][service + '_endpoint'].rstrip('/')14 responder = OpenStackResponder(disp.mount, endpoint)15 for endpoint in disp.get_unused_endpoints():16 disp.set_handler(endpoint, responder)17class OpenstackStream(object):18 def __init__(self, stream, size=None):19 self.stream = stream20 self.size = size21 def __len__(self):22 return self.size23 def read(self, size=None):24 return self.stream.read(size=size)25 def __iter__(self):26 return self.stream.__iter__()27 def __next__(self):28 return self.stream.__next__()29 next = __next__30class OpenStackResponder(object):31 def __init__(self, mount, endpoint):32 self.mount = mount33 self.endpoint = endpoint34 def _standard_responder(self, req, resp, **_):35 data = None36 if (req.method == 'POST' or req.method == 'PUT'):37 if req.content_length:38 data = OpenstackStream(req.stream, size=req.content_length)39 relative_uri = req.relative_uri40 if self.mount:41 relative_uri = relative_uri.replace(self.mount, '', 1)42 endpoint = self.endpoint + relative_uri43 os_resp = requests.request(req.method,44 endpoint,45 data=data,46 headers=req.headers,47 stream=True)48 resp.status = os_resp.status_code49 content_type = os_resp.headers.pop(50 'Content-Type', 'application/json').split(';', 1)[0]51 # Hack for test_delete_image_blank_id test. Somehow text/html comes52 # back as the content-type when it's supposed to be text/plain.53 if content_type == 'text/html':54 content_type = 'text/plain; charset=UTF-8'55 resp.content_type = content_type56 resp.stream_len = os_resp.headers.pop('Content-Length', 0)57 resp.set_headers(os_resp.headers)58 resp.stream = os_resp.raw59 on_get = _standard_responder60 on_post = _standard_responder61 on_put = _standard_responder62 on_delete = _standard_responder63 on_head = _standard_responder64 on_trace = _standard_responder65 on_patch = _standard_responder66 on_connect = _standard_responder...
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!!