tests/_fixtures.py
def _flask_impl(mocked_config):
    """Implementation of fixture for injecting a Flask test client into a test function."""
    # Need to import this late as importing this module has sideeffcts on loging that
    from dirbs.api import app

    # We need to save the old URL map and view functions before adding out test_errors route below so
    # we can restore the state of the app during the fixture teardown
    old_url_map = copy.copy(app.url_map)
    old_view_functions = copy.copy(app.view_functions)

    @app.route('/test_errors')
    def test_errors():
        """Dummy route to test uncaught exception handling more easily."""
        raise ValueError('Testing unknown failures')

    app.testing = True
    app.debug = False
    # we need to copy the app config after setting debug(False) and testing(True) in order to have a copy of those
    # app configurations. (At the beginning of this fixture debug is set to true).
    # The fixture will then use this copy to restore those configuration after yielding the client,
    # enforcing debug to be set to False. If debug is set to True, it is possible to
    # get a setup function error.
    old_config = copy.copy(app.config)
    app.config['DIRBS_CONFIG'] = mocked_config
    client = app.test_client()
    ctx = app.test_request_context()
    ctx.push()
    yield client
    app.url_map = old_url_map
    app.view_functions = old_view_functions
    app.config = old_config
    # Reset the _got_first_request flag so that before_first_request funcs trigger every time
    app._got_first_request = False
    ctx.pop()
Implementation of fixture for injecting a Flask test client into a test function.
Implementation of fixture for injecting a Flask test client into a test function.
Implementation of fixture for injecting a Flask test client into a test function .
def _flask_impl(mocked_config):
    from dirbs.api import app
    old_url_map = copy.copy(app.url_map)
    old_view_functions = copy.copy(app.view_functions)
    @app.route('/test_errors')
    def test_errors():
        raise ValueError('Testing unknown failures')
    app.testing = True
    app.debug = False
    old_config = copy.copy(app.config)
    app.config['DIRBS_CONFIG'] = mocked_config
    client = app.test_client()
    ctx = app.test_request_context()
    ctx.push()
    yield client
    app.url_map = old_url_map
    app.view_functions = old_view_functions
    app.config = old_config
    app._got_first_request = False
    ctx.pop()
def _flask_impl ( mocked_config ) : from dirbs . api import app old_url_map = copy . copy ( app . url_map ) old_view_functions = copy . copy ( app . view_functions ) @ app . route ( '/test_errors' ) def test_errors ( ) : """Dummy route to test uncaught exception handling more easily.""" raise ValueError ( 'Testing unknown failures' ) app . testing = True app . debug = False old_config = copy . copy ( app . config ) app . config [ 'DIRBS_CONFIG' ] = mocked_config client = app . test_client ( ) ctx = app . test_request_context ( ) ctx . push ( ) yield client app . url_map = old_url_map app . view_functions = old_view_functions app . config = old_config app . _got_first_request = False ctx . pop ( )
Implementation of fixture for injecting a Flask test client into a test function.
Implementation of fixture for injecting a Flask test client into a test function .
"""Implementation of fixture for injecting a Flask test client into a test function.""" # Need to import this late as importing this module has sideeffcts on loging that # We need to save the old URL map and view functions before adding out test_errors route below so # we can restore the state of the app during the fixture teardown """Dummy route to test uncaught exception handling more easily.""" # we need to copy the app config after setting debug(False) and testing(True) in order to have a copy of those # app configurations. (At the beginning of this fixture debug is set to true). # The fixture will then use this copy to restore those configuration after yielding the client, # enforcing debug to be set to False. If debug is set to True, it is possible to # get a setup function error. # Reset the _got_first_request flag so that before_first_request funcs trigger every time
mocked_config