How to use parse_content_type method in gabbi

Best Python code snippet using gabbi_python

mime.py

Source:mime.py Github

copy

Full Screen

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",...

Full Screen

Full Screen

middleware.py

Source:middleware.py Github

copy

Full Screen

...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)...

Full Screen

Full Screen

test_utils.py

Source:test_utils.py Github

copy

Full Screen

...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'))...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run gabbi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful