def test_parse_firefox_accept_header(self): accept = ('text/html,application/xhtml+xml,application/xml;q=0.9,' '*/*;q=0.8') expected = [('text', 'html'), ('application', 'xhtml+xml'), ('application', 'xml'), ('*', '*')] self.assertEqual(expected, parse_accept_header(accept))
def test_parse_firefox_accept_header(self): accept = "text/html,application/xhtml+xml,application/xml;q=0.9," "*/*;q=0.8" expected = [ ("text", "html"), ("application", "xhtml+xml"), ("application", "xml"), ("*", "*"), ] self.assertEqual(expected, parse_accept_header(accept))
def test_parse_chrome_accept_header(self): accept = ('text/html,application/xhtml+xml,application/xml;q=0.9,' 'image/webp,*/*;q=0.8') expected = [('text', 'html'), ('application', 'xhtml+xml'), ('application', 'xml'), ('image', 'webp'), ('*', '*')] self.assertEqual(expected, parse_accept_header(accept))
def test_parse_jquery_json_accept_header(self): accept = ('text/javascript, application/javascript, ' 'application/ecmascript, application/x-ecmascript, ' '*/*; q=0.01') expected = [('text', 'javascript'), ('application', 'javascript'), ('application', 'ecmascript'), ('application', 'x-ecmascript'), ('*', '*')] self.assertEqual(expected, parse_accept_header(accept))
def serviceDirective( _context, method, accept, factory, for_, permission, layer=IDefaultBrowserLayer, name=u"", ): _handle_for(_context, for_) media_types = parse_accept_header(accept) for media_type in media_types: service_id = register_service(method.upper(), media_type) view_name = service_id + name # We need a service for CORS preflight processing but we don't get the # desired Accept header in the preflight request. Thus we just register # the current service_id for the given method. register_method_for_preflight(method.upper(), service_id) # Create a new class. We'll execute some security declarations on it # and don't want to modify the original class. cdict = getSecurityInfo(factory) cdict["__name__"] = view_name cdict["method"] = method.upper() new_class = type(factory.__name__, (factory, BrowserView), cdict) _context.action( discriminator=("plone.rest:service", method, media_type, for_, name, layer), callable=handler, args=( "registerAdapter", new_class, (for_, layer), Interface, view_name, _context.info, ), ) _context.action( discriminator=("plone.rest:protectClass", new_class), callable=protectClass, args=(new_class, permission), ) _context.action( discriminator=("plone.rest:InitializeClass", new_class), callable=InitializeClass, args=(new_class, ), )
def test_parse_chrome_accept_header(self): accept = ("text/html,application/xhtml+xml,application/xml;q=0.9," "image/webp,*/*;q=0.8") expected = [ ("text", "html"), ("application", "xhtml+xml"), ("application", "xml"), ("image", "webp"), ("*", "*"), ] self.assertEqual(expected, parse_accept_header(accept))
def test_parse_jquery_json_accept_header(self): accept = ("text/javascript, application/javascript, " "application/ecmascript, application/x-ecmascript, " "*/*; q=0.01") expected = [ ("text", "javascript"), ("application", "javascript"), ("application", "ecmascript"), ("application", "x-ecmascript"), ("*", "*"), ] self.assertEqual(expected, parse_accept_header(accept))
def serviceDirective( _context, method, accept, factory, for_, permission, layer=IDefaultBrowserLayer, name=u'', ): _handle_for(_context, for_) media_types = parse_accept_header(accept) for media_type in media_types: service_id = register_service(method.upper(), media_type) view_name = service_id + name # We need a service for CORS preflight processing but we don't get the # desired Accept header in the preflight request. Thus we just register # the current service_id for the given method. register_method_for_preflight(method.upper(), service_id) # Create a new class. We'll execute some security declarations on it # and don't want to modify the original class. cdict = getSecurityInfo(factory) cdict['__name__'] = view_name cdict['method'] = method.upper() new_class = type(factory.__name__, (factory, BrowserView), cdict) _context.action( discriminator=('plone.rest:service', method, media_type, for_, name, layer), callable=handler, args=('registerAdapter', new_class, (for_, layer), Interface, view_name, _context.info), ) _context.action( discriminator=('plone.rest:protectClass', new_class), callable=protectClass, args=(new_class, permission) ) _context.action( discriminator=('plone.rest:InitializeClass', new_class), callable=InitializeClass, args=(new_class,) )
def test_parse_application_json_accept_header(self): accept = "application/json" expected = [("application", "json")] self.assertEqual(expected, parse_accept_header(accept))
def test_parse_invalid_accept_header(self): self.assertEqual([], parse_accept_header("invalid"))
def test_parse_all_media_types_accept_header(self): self.assertEqual([("*", "*")], parse_accept_header("*/*"))
def test_parse_invalid_accept_header(self): self.assertEqual([], parse_accept_header('invalid'))
def test_parse_all_media_types_accept_header(self): self.assertEqual([('*', '*')], parse_accept_header('*/*'))
def test_parse_application_json_accept_header(self): accept = 'application/json' expected = [('application', 'json')] self.assertEqual(expected, parse_accept_header(accept))