示例#1
0
def initialize_flask():
    """Make sure that the flask application is properly configured before it
    serves any requests
    """

    server_conf = app.config['SERVER']
    backend_conf = app.config['BACKENDS']

    views.manager = BackendManager(backend_conf)

    ratelimit = server_conf.get('ratelimit', None)
    if ratelimit is not None and ratelimit.get('enabled', False):
        RateLimit.enable(limit=ratelimit['limit'], per=ratelimit['per'])

    def deinitialize_manager():
        """Do any cleanup that needs to be done (for backends in particular)
        before the server terminates.
        """

        log.info("Shutting down server...")
        views.manager.shutdown()

    # Cleanup the server on ^C
    import atexit
    atexit.register(deinitialize_manager)
示例#2
0
def initialize_flask():
    """Make sure that the flask application is properly configured before it
    serves any requests
    """

    server_conf = app.config['SERVER']
    backend_conf = app.config['BACKENDS']

    views.manager = BackendManager(backend_conf)

    ratelimit = server_conf.get('ratelimit', None)
    if ratelimit is not None and ratelimit.get('enabled', False):
        RateLimit.enable(limit=ratelimit['limit'], per=ratelimit['per'])

    def deinitialize_manager():
        """Do any cleanup that needs to be done (for backends in particular)
        before the server terminates.
        """

        log.info("Shutting down server...")
        views.manager.shutdown()

    # Cleanup the server on ^C
    import atexit
    atexit.register(deinitialize_manager)
示例#3
0
    def setup_class(self):
        views.manager = BackendManager({'dummy': {'enabled': True}})
        app.config['TESTING'] = True

        # 5 reqs / 1 sec
        # Do this two different ways so when test is run as a standalone, still
        # works. Probably indicative of bad design, but works for purposes of
        # this test.
        RateLimit.enable(limit=5, per=1)
        app.config['SERVER']['ratelimit'] = {
            'enabled': True,
            'limit': 5,
            'per': 1
        }

        self.client = app.test_client()