Best Python code snippet using gabbi_python
simple_wsgi.py
Source:simple_wsgi.py
...29 request_url = environ.get('REQUEST_URI',30 environ.get('RAW_URI', 'unknown'))31 accept_header = environ.get('HTTP_ACCEPT')32 content_type_header = environ.get('CONTENT_TYPE', '')33 request_url = self._fully_qualify(environ, request_url)34 if accept_header:35 response_content_type = accept_header36 else:37 response_content_type = 'application/json'38 headers = [39 ('X-Gabbi-method', request_method),40 ('Content-Type', response_content_type),41 ('X-Gabbi-url', request_url),42 ]43 if request_method == 'DIE':44 raise Exception('because you asked me to')45 if request_method not in METHODS:46 headers.append(47 ('Allow', ', '.join(METHODS)))48 start_response('405 Method Not Allowed', headers)49 return []50 if request_method.startswith('P'):51 body = environ['wsgi.input'].read()52 if body:53 if not content_type_header:54 start_response('400 Bad request', headers)55 return []56 if content_type_header == 'application/json':57 body_data = json.loads(body.decode('utf-8'))58 if query_data:59 query_data.update(body_data)60 else:61 query_data = body_data62 headers.append(('Location', request_url))63 start_response('200 OK', headers)64 query_output = json.dumps(query_data)65 return [query_output.encode('utf-8')]66 @staticmethod67 def _fully_qualify(environ, url):68 """Turn a URL path into a fully qualified URL."""69 path, query, fragment = urlparse.urlsplit(url)[2:]70 server_name = environ.get('SERVER_NAME')71 server_port = environ.get('SERVER_PORT')72 server_scheme = environ.get('wsgi.url_scheme')73 if server_port not in ['80', '443']:74 netloc = '%s:%s' % (server_name, server_port)75 else:76 netloc = server_name77 return urlparse.urlunsplit((server_scheme, netloc, path,...
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!!