def make_application(**settings):
    application = web.Application([web.url(r'/', SimpleHandler)], **settings)
    content.set_default_content_type(application,
                                     'application/json',
                                     encoding='utf-8')
    content.add_transcoder(application, transcoders.MsgPackTranscoder())
    content.add_transcoder(application, transcoders.JSONTranscoder())
    return application
Esempio n. 2
0
 def __init__(self, simplify_error_response=True):
     self._exceptions = []
     self._finish = None
     self._json = transcoders.JSONTranscoder()
     self._msgpack = transcoders.MsgPackTranscoder()
     self._responses = []
     self._start = time.time()
     self._simplify_error_response = simplify_error_response
Esempio n. 3
0
def make_application(**settings) -> app.Application:
    """Create the web application instance after building the settings

    :param dict settings: kwarg settings passed in for the application

    """
    _set_default_settings(settings)
    if settings['environment'] in ('development', 'testing'):
        os.environ.pop('SENTRY_DSN', None)
        settings.setdefault('debug', True)

    urls = [
        web.url(r'/static/(.*)', web.StaticFileHandler,
                {'path': settings['static_path']})
    ]
    urls += endpoints.URLS

    settings['permissions'] = _get_permissions(urls)

    application = Application(
        urls,
        log_function=correlation.mixins.correlation_id_logger,
        **settings)

    # Content handling setup
    content.install(application, 'application/json', 'utf-8')
    content.add_transcoder(application, transcoders.JSONTranscoder())
    content.add_transcoder(
        application, transcoders.JSONTranscoder('application/json-patch+json'))
    content.add_transcoder(application, transcoders.MsgPackTranscoder())
    content.add_transcoder(application, html.HTMLTranscoder())

    # Instrument which libraries to include in sentry reports
    """
    sentry.install(
        app,
        include_paths=[
            'aiopg',
            'aioredis',
            'arrow',
            'imbi',
            'jsonpatch',
            'jsonschema',
            'sprockets.http',
            'sprockets.handlers.status',
            'sprockets.mixins.correlation',
            'sprockets.mixins.mediatype',
            'sprockets.mixins.metrics',
            'sprockets_postgres'],
        release=__version__,
        tags={'environment': settings['environment']})
    """
    return application
Esempio n. 4
0
 def test_that_accept_header_with_suffix_is_obeyed(self):
     content.add_transcoder(
         self._app,
         transcoders.MsgPackTranscoder(content_type='expected/content'),
         'application/vendor+msgpack')
     response = self.fetch('/',
                           method='POST',
                           body='{}',
                           headers={
                               'Accept': 'application/vendor+msgpack',
                               'Content-Type': 'application/json'
                           })
     self.assertEqual(response.code, 200)
     self.assertEqual(response.headers['Content-Type'], 'expected/content')
 def setUp(self):
     super(MsgPackTranscoderTests, self).setUp()
     self.transcoder = transcoders.MsgPackTranscoder()
Esempio n. 6
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.__hcm_json = transcoders.JSONTranscoder()
     self.__hcm_msgpack = transcoders.MsgPackTranscoder()
     self.simplify_error_response = True