Best Python code snippet using gabbi_python
mime.py
Source: mime.py
2def check_other(content_type, content) -> bool:3 return True4# https://mimesniff.spec.whatwg.org/#json-mime-type5def check_json(content_type, content) -> bool:6 content_type = parse_content_type(content_type)7 if content_type[1].endwith("json"):8 return True9 return False10# multipart/form-data, application/x-www-form-urlencoded11def check_form(content_type, content) -> bool:12 content_type = parse_content_type(content_type)13 t = "{}/{}".format(content_type[0], content[1])14 form_list = [15 'multipart/form-data',16 'application/x-www-form-urlencoded',17 ]18 if t in form_list:19 return True20 return False21# https://mimesniff.spec.whatwg.org/#html-mime-type22def check_html(content_type, content) -> bool:23 content_type = parse_content_type(content_type)24 t = "{}/{}".format(content_type[0], content[1])25 html_list = [26 'text/html',27 ]28 if t in html_list:29 return True30 return False31# https://mimesniff.spec.whatwg.org/#xml-mime-type32def check_xml(content_type, content) -> bool:33 content_type = parse_content_type(content_type)34 if content_type[1].endwith("xml"):35 return True36 return False37# https://mimesniff.spec.whatwg.org/#image-mime-type38def check_image(content_type, content) -> bool:39 content_type = parse_content_type(content_type)40 if content_type[0].endwith("image"):41 return True42 return False43# https://mimesniff.spec.whatwg.org/#font-mime-type44def check_font(content_type, content) -> bool:45 content_type = parse_content_type(content_type)46 if content_type[0].endwith("font"):47 return True48 font_list = [49 'application/font-cff',50 'application/font-off',51 'application/font-sfnt',52 'application/font-ttf',53 'application/font-woff',54 'application/vnd.ms-fontobject',55 'application/vnd.ms-opentype',56 ]57 t = "{}/{}".format(content_type[0], content[1])58 if t in font_list:59 return True60 return False61def check_css(content_type, content) -> bool:62 content_type = parse_content_type(content_type)63 t = "{}/{}".format(content_type[0], content[1])64 css_list = [65 "text/css",66 ]67 if t in css_list:68 return True69 return False70def check_js(content_type, content) -> bool:71 content_type = parse_content_type(content_type)72 t = "{}/{}".format(content_type[0], content[1])73 js_list = [74 "application/ecmascript",75 "application/javascript",76 "application/x-ecmascript",77 "application/x-javascript",78 "text/ecmascript",79 "text/javascript",80 "text/javascript1.0",81 "text/javascript1.1",82 "text/javascript1.2",83 "text/javascript1.3",84 "text/javascript1.4",85 "text/javascript1.5",...
middleware.py
Source: middleware.py
...5 def __init__(self, app: Flask):6 self.app = app.wsgi_app7 self.content_types = app.config.get('ALLOWED_CONTENT_TYPES')8 @staticmethod9 def parse_content_type(content_type: str) -> str:10 """Parser a request Content-Type.11 Parameters12 ----------13 content_type : str14 Request Content Type.15 Returns16 -------17 str18 Parsed request Content Type.19 References20 ----------21 RFC 1341 - MIME (Multipurpose Internet Mail Extensions):22 https://tools.ietf.org/html/rfc134123 Examples24 --------25 >>> from app.middleware import Middleware as m26 >>> m.parse_content_type('multipart/form-data; boundary=something')27 multipart/form-data28 >>> m.parse_content_type('text/html; charset=utf-8')29 text/html30 """31 if content_type is None:32 parsed_content_type = ''33 else:34 parsed_content_type = content_type.split(';')[0] \35 if content_type.find(';') else content_type36 return parsed_content_type37 def __call__(self, environ, start_response):38 request = Request(environ)39 is_api_request = (request.path[1:4] == 'api')40 if is_api_request:41 content_type = self.parse_content_type(request.content_type)42 accept_mimetypes = request.accept_mimetypes.accept_json # Swagger43 if content_type in self.content_types or accept_mimetypes:44 return self.app(environ, start_response)45 response = Response(response='{"message": "Content type no valid"}',46 mimetype='application/json',47 status=400)48 return response(environ, start_response)...
test_utils.py
Source: test_utils.py
...8 from respite.utils import parse_http_accept_header9 input = 'application/xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'10 expected_output = ['application/xml', 'image/png', 'text/html', 'text/plain', '*/*']11 assert parse_http_accept_header(input) == expected_output12def test_parse_content_type():13 from respite.utils import parse_content_type14 assert_equal(('text/html', 'ISO-8859-1'), parse_content_type('text/html'))15 assert_equal(('text/html', 'ISO-8859-4'), parse_content_type('text/html; charset=ISO-8859-4'))16 assert_equal(('application/json', 'UTF-8'), parse_content_type('application/json'))...
Check out the latest blogs from LambdaTest on this topic:
Enterprise resource planning (ERP) is a form of business process management software—typically a suite of integrated applications—that assists a company in managing its operations, interpreting data, and automating various back-office processes. The introduction of a new ERP system is analogous to the introduction of a new product into the market. If the product is not handled appropriately, it will fail, resulting in significant losses for the business. Most significantly, the employees’ time, effort, and morale would suffer as a result of the procedure.
Have you ever struggled with handling hidden elements while automating a web or mobile application? I was recently automating an eCommerce application. I struggled with handling hidden elements on the web page.
Agile has unquestionable benefits. The mainstream method has assisted numerous businesses in increasing organizational flexibility as a result, developing better, more intuitive software. Distributed development is also an important strategy for software companies. It gives access to global talent, the use of offshore outsourcing to reduce operating costs, and round-the-clock development.
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
To understand the agile testing mindset, we first need to determine what makes a team “agile.” To me, an agile team continually focuses on becoming self-organized and cross-functional to be able to complete any challenge they may face during a project.
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!!