Exemple #1
0
def zodb_filter_middleware(
    app,
    global_conf,  # A dict containing the ['DEFAULT'] section of the ini.
    configuration,
    initializer=None,
    key="zodb.connection",
    transaction_key='transaction.manager'):
    """
    factory for :py:class:ZODBAppFactory

    This middleware factory is compatible with the filter_app
    prototype from `PasteDeploy`. It can, however, be used with
    any WSGI server if properly called.

    :param initializer: an optional ZODB initializer
      module.dotted.name:callable,
      eg: 'cromlech.zodb.utils:initialize_applications'
    :param transaction: does the middelware needs to manage the transaction

    for other params see :py:meth:ZODBApp.__init__
    """
    if initializer is not None:
        # initializer is a string: py_module_path:class_or_function
        initializer = eval_loader(initializer)

    # configuration is an XML-based ZODB conf
    db = init_db(configuration, initializer)

    return ZODBApp(
        app, db, key, transaction_key,
        transaction_manager_factory=environ_transaction_manager)
Exemple #2
0
def test_eval_loader():
    assert eval_loader('cromlech.zodb.utils:eval_loader') is eval_loader
    assert (eval_loader('cromlech.zodb.tests.fixture:Foo').__doc__ ==
            "class to test eval_loader")
    with pytest.raises(RuntimeError):
        eval_loader(':foo')
    with pytest.raises(ImportError):
        # module does not exists
        eval_loader('cromlech.zodb.doesnotexiste:id')
    with pytest.raises(ImportError):
        # object inside module does not exists
        eval_loader('cromlech.zodb.tests.fixture:Bar')