Beispiel #1
0
def test_init_db_bad_conf():
    configuration = """
        <zodb>
            <UNKNOWN_storage>
            </UNKNOWN_storage>
        </zodb>"""
    with pytest.raises(ZConfig.ConfigurationSyntaxError):
        init_db(configuration, add_foo)
Beispiel #2
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)
Beispiel #3
0
 def create(cls, gc, session_key='session.key', environ_key='zodb.key',
            conf=None, name='app', root=None, **kws):
     if root is None:
         root = cls.root
     db = init_db(conf, make_application(name, root))
     app = cls(session_key, environ_key, name)
     return ZODBApp(app, db, key=environ_key)
Beispiel #4
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:ZODBApp

    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 configuration: XML-based ZODB conf
    :param initializer: callable that takes 'db' as a parameter.
    :param key: environ key used to retrieve an existing connection
    :param transaction_key: environ key used to pass the transaction around.

    for other params see :py:meth:ZODBApp.__init__
    """
    db = init_db(configuration, initializer)

    return ZODBApp(
        app, db, key, transaction_key,
        transaction_manager_factory=environ_transaction_manager)
Beispiel #5
0
def zodb_aware_poller(url, timeout=None, db_conf=None, zodb_conf=None, **data):
    queues = dict(getUtilitiesFor(IReceptionQueue))
    receiver = get_reader(url)
    tm = transaction.TransactionManager()
    db = init_db(open(db_conf, 'r').read())
    with ZODBConnection(db, transaction_manager=tm) as zodb:
        with tm:
            data['db_root'] = zodb
            receiver.poll(queues, timeout=timeout, **data)
Beispiel #6
0
def test_init_db():
    configuration = """
        <zodb>
        <demostorage>
        </demostorage>
        </zodb>"""
    db = init_db(configuration, add_foo)
    conn = db.open()
    assert conn.root()['foo'] is foo
Beispiel #7
0
 def create(cls,
            gc,
            session_key='session.key',
            environ_key='zodb.key',
            conf=None,
            name='app',
            root=None,
            **kws):
     if root is None:
         root = cls.root
     db = init_db(conf, make_application(name, root))
     app = cls(session_key, environ_key, name)
     return ZODBApp(app, db, key=environ_key)