示例#1
0
 def test_media_router_serve_only(self):
     router = MediaRouter('/', serve_only=('json', 'png'))
     self.assertIsInstance(router._serve_only, set)
     self.assertEqual(len(router._serve_only), 2)
     self.assertEqual(router(test_wsgi_environ('/foo')), None)
     self.assertEqual(router(test_wsgi_environ('/foo/bla')), None)
     self.assertRaises(Http404, router, test_wsgi_environ('/foo/bla.png'))
示例#2
0
文件: wsgi.py 项目: LJS109/pulsar
 def test_parse_form_data(self):
     environ = wsgi.test_wsgi_environ()
     self.assertRaises(MultipartError, parse_form_data, environ,
                       strict=True)
     environ = wsgi.test_wsgi_environ(method='POST')
     self.assertRaises(MultipartError, parse_form_data, environ,
                       strict=True)
示例#3
0
 def test_parse_form_data(self):
     environ = wsgi.test_wsgi_environ()
     self.assertRaises(MultipartError, parse_form_data, environ,
                       strict=True)
     environ = wsgi.test_wsgi_environ(method='POST')
     self.assertRaises(MultipartError, parse_form_data, environ,
                       strict=True)
示例#4
0
 def test_media_router_serve_only(self):
     router = MediaRouter('/', serve_only=('json', 'png'))
     self.assertIsInstance(router._serve_only, set)
     self.assertEqual(len(router._serve_only), 2)
     self.assertEqual(router(test_wsgi_environ('/foo')), None)
     self.assertEqual(router(test_wsgi_environ('/foo/bla')), None)
     self.assertRaises(Http404, router, test_wsgi_environ('/foo/bla.png'))
示例#5
0
文件: app.py 项目: pvanderlinden/lux
    def wsgi_request(self,
                     environ=None,
                     loop=None,
                     path=None,
                     app_handler=None,
                     urlargs=None,
                     **kw):
        '''Create a :class:`.WsgiRequest` from a wsgi ``environ`` and set the
        ``app`` attribute in the cache.
        Additional keyed-valued parameters can be inserted.
        '''
        if not environ:
            # No WSGI environment, build a test one
            environ = test_wsgi_environ(path=path, loop=loop, **kw)
        request = wsgi_request(environ,
                               app_handler=app_handler,
                               urlargs=urlargs)
        environ['error.handler'] = self.config['ERROR_HANDLER']
        environ['default.content_type'] = self.config['DEFAULT_CONTENT_TYPE']
        # Check if pulsar is serving the application
        if 'pulsar.cfg' not in environ:
            if not self.cfg:
                self.cfg = pulsar.Config(debug=self.debug)
            environ['pulsar.cfg'] = self.cfg

        request.cache.app = self
        return request
示例#6
0
 def test_handle_wsgi_error(self):
     handler = lambda request, exc: 'exception: %s' % exc
     environ = wsgi.test_wsgi_environ(extra={'error.handler': handler})
     try:
         raise ValueError('just a test')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'exception: just a test', ))
示例#7
0
文件: wsgi.py 项目: LoganTK/pulsar
 def test_handle_wsgi_error(self):
     environ = wsgi.test_wsgi_environ(
         extra={'error.handler': lambda request, failure: 'bla'})
     try:
         raise ValueError('just a test')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'bla',))
示例#8
0
 def test_handle_wsgi_error(self):
     handle500 = lambda request, exc: 'exception: %s' % exc
     environ = wsgi.test_wsgi_environ(
         extra={'error.handlers': {500: handle500}})
     try:
         raise ValueError('just a test')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'exception: just a test',))
示例#9
0
 def test_handle_wsgi_error(self):
     environ = wsgi.test_wsgi_environ(extra=
                         {'error.handler': lambda request, failure: 'bla'})
     try:
         raise ValueError('just a test')
     except ValueError:
         failure = pulsar.Failure(sys.exc_info())
         failure.mute()
         response = wsgi.handle_wsgi_error(environ, failure)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'bla',))
示例#10
0
文件: wsgi.py 项目: LJS109/pulsar
 def test_handle_wsgi_error_debug(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg})
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content_type, None)
     self.assertEqual(len(response.content), 1)
示例#11
0
文件: wsgi.py 项目: luffyhwl/pulsar
    def test_handle_wsgi_error(self):
        def handler(request, exc):
            return "exception: %s" % exc

        environ = wsgi.test_wsgi_environ(extra={"error.handler": handler})
        try:
            raise ValueError("just a test")
        except ValueError as exc:
            response = wsgi.handle_wsgi_error(environ, exc)
        self.assertEqual(response.status_code, 500)
        self.assertEqual(response.content, (b"exception: just a test",))
示例#12
0
 def test_handle_wsgi_error_debug(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg})
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content_type, None)
     self.assertEqual(len(response.content), 1)
示例#13
0
    def test_response_wrapper(self):
        def response_wrapper(callable, response):
            raise pulsar.PermissionDenied('Test Response Wrapper')

        router = HttpBin('/', response_wrapper=response_wrapper)

        environ = test_wsgi_environ()
        try:
            router(environ, None)
        except pulsar.PermissionDenied as exc:
            self.assertEqual(str(exc), 'Test Response Wrapper')
        else:
            raise RuntimeError

        environ = test_wsgi_environ('/get')
        try:
            router(environ, None)
        except pulsar.PermissionDenied as exc:
            self.assertEqual(str(exc), 'Test Response Wrapper')
        else:
            raise RuntimeError
示例#14
0
    def test_response_wrapper(self):

        def response_wrapper(callable, response):
            raise pulsar.PermissionDenied('Test Response Wrapper')

        router = HttpBin('/', response_wrapper=response_wrapper)

        environ = test_wsgi_environ()
        try:
            router(environ, None)
        except pulsar.PermissionDenied as exc:
            self.assertEqual(str(exc), 'Test Response Wrapper')
        else:
            raise RuntimeError

        environ = test_wsgi_environ('/get')
        try:
            router(environ, None)
        except pulsar.PermissionDenied as exc:
            self.assertEqual(str(exc), 'Test Response Wrapper')
        else:
            raise RuntimeError
示例#15
0
 def test_handle_wsgi_error(self):
     environ = wsgi.test_wsgi_environ(
         extra={
             'error.handler': lambda request, failure: 'bla'
         })
     try:
         raise ValueError('just a test')
     except ValueError:
         failure = pulsar.Failure(sys.exc_info())
         failure.mute()
         response = wsgi.handle_wsgi_error(environ, failure)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content, (b'bla', ))
示例#16
0
文件: app.py 项目: pombredanne/lux
 def wsgi_request(self, environ=None, **kw):
     '''Create a :class:`WsgiRequest` from a wsgi ``environ`` and set the
     ``app`` attribute in the cache.
     Additional keyed-valued parameters can be inserted.
     '''
     if not environ:
         # No WSGI environment, build a test one
         environ = test_wsgi_environ()
     if kw:
         environ.update(kw)
     request = WsgiRequest(environ)
     environ['error.handler'] = self.config['ERROR_HANDLER']
     request.cache.app = self
     return request
示例#17
0
 def test_handle_wsgi_error_debug(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg})
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError:
         exc_info = sys.exc_info()
     failure = pulsar.Failure(exc_info)
     failure.mute()
     response = wsgi.handle_wsgi_error(environ, failure)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content_type, None)
     self.assertEqual(len(response.content), 1)
示例#18
0
文件: wsgi.py 项目: luffyhwl/pulsar
 def test_handle_wsgi_error_debug_html(self):
     cfg = self.cfg.copy()
     cfg.set("debug", True)
     headers = [("Accept", "*/*")]
     environ = wsgi.test_wsgi_environ(extra={"pulsar.cfg": cfg}, headers=headers)
     try:
         raise ValueError("just a test for debug wsgi error handler")
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     html = response.content[0]
     self.assertEqual(response.content_type, "text/html")
     self.assertTrue(html.startswith(b"<!DOCTYPE html>"))
     self.assertTrue(b"<title>500 Internal Server Error</title>" in html)
示例#19
0
 def wsgi_request(self, environ=None, **kw):
     '''Create a :class:`WsgiRequest` from a wsgi ``environ`` and set the
     ``app`` attribute in the cache.
     Additional keyed-valued parameters can be inserted.
     '''
     if not environ:
         # No WSGI environment, build a test one
         environ = test_wsgi_environ()
     if kw:
         environ.update(kw)
     request = WsgiRequest(environ)
     environ['error.handler'] = self.config['ERROR_HANDLER']
     request.cache.app = self
     return request
示例#20
0
 def test_handle_wsgi_error_debug(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg})
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError:
         exc_info = sys.exc_info()
     failure = pulsar.Failure(exc_info)
     failure.mute()
     response = wsgi.handle_wsgi_error(environ, failure)
     self.assertEqual(response.status_code, 500)
     self.assertEqual(response.content_type, None)
     self.assertEqual(len(response.content), 1)
示例#21
0
 def test_handle_wsgi_error_debug_html(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     headers = [('Accept', '*/*')]
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg},
                                      headers=headers)
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     html = response.content[0]
     self.assertEqual(response.content_type, 'text/html')
     self.assertTrue(html.startswith(b'<!DOCTYPE html>'))
     self.assertTrue(b'<title>500 Internal Server Error</title>' in html)
示例#22
0
文件: wsgi.py 项目: LJS109/pulsar
 def test_handle_wsgi_error_debug_html(self):
     cfg = self.cfg.copy()
     cfg.set('debug', True)
     headers = [('Accept', '*/*')]
     environ = wsgi.test_wsgi_environ(extra={'pulsar.cfg': cfg},
                                      headers=headers)
     try:
         raise ValueError('just a test for debug wsgi error handler')
     except ValueError as exc:
         response = wsgi.handle_wsgi_error(environ, exc)
     self.assertEqual(response.status_code, 500)
     html = response.content[0]
     self.assertEqual(response.content_type, 'text/html')
     self.assertTrue(html.startswith(b'<!DOCTYPE html>'))
     self.assertTrue(b'<title>500 Internal Server Error</title>' in html)
示例#23
0
文件: app.py 项目: pvanderlinden/lux
    def wsgi_request(self, environ=None, loop=None, path=None,
                     app_handler=None, urlargs=None, **kw):
        '''Create a :class:`.WsgiRequest` from a wsgi ``environ`` and set the
        ``app`` attribute in the cache.
        Additional keyed-valued parameters can be inserted.
        '''
        if not environ:
            # No WSGI environment, build a test one
            environ = test_wsgi_environ(path=path, loop=loop, **kw)
        request = wsgi_request(environ, app_handler=app_handler,
                               urlargs=urlargs)
        environ['error.handler'] = self.config['ERROR_HANDLER']
        environ['default.content_type'] = self.config['DEFAULT_CONTENT_TYPE']
        # Check if pulsar is serving the application
        if 'pulsar.cfg' not in environ:
            if not self.cfg:
                self.cfg = pulsar.Config(debug=self.debug)
            environ['pulsar.cfg'] = self.cfg

        request.cache.app = self
        return request
示例#24
0
 def request(self, **kwargs):
     environ = wsgi.test_wsgi_environ(**kwargs)
     return wsgi.WsgiRequest(environ)
示例#25
0
 def request(self, **kwargs):
     environ = wsgi.test_wsgi_environ(**kwargs)
     return wsgi.WsgiRequest(environ)