async def test_resources():
    mailer = SMTPMailer(ssl='contextresource')
    context = Context()
    sslcontext = ssl.create_default_context()
    context.publish_resource(sslcontext, 'contextresource')
    await mailer.start(context)
    assert mailer.ssl is sslcontext
Beispiel #2
0
async def test_single_client(event_loop):
    ctx = Context()
    component = WAMPComponent(ssl='default', serializer='default')
    ssl_context = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
    serializer = JSONSerializer()
    ctx.publish_resource(serializer, types=[Serializer])
    ctx.publish_resource(ssl_context)
    await component.start(ctx)

    assert isinstance(ctx.wamp, WAMPClient)
    assert ctx.wamp.ssl is ssl_context
    assert ctx.wamp.serializer is serializer
Beispiel #3
0
    async def test_get_resources_include_parents(self, context):
        subcontext = Context(context)
        resource1 = context.publish_resource(6, 'int1')
        resource2 = subcontext.publish_resource(8, 'int2')
        resource3 = context.publish_resource('foo', 'str')

        assert subcontext.get_resources() == [resource1, resource2, resource3]
        assert subcontext.get_resources(include_parents=False) == [resource2]
async def test_finish_commit(raise_exception, executor, commit_executor, tmpdir):
    """
    Tests that the session is automatically committed if and only if the context was not exited
    with an exception.

    """
    db_path = tmpdir.join('test.db')
    session = dict(commit_executor=executor if commit_executor == 'instance' else commit_executor)
    component = SQLAlchemyComponent(url={'drivername': 'sqlite', 'database': str(db_path)},
                                    session=session)
    ctx = Context()
    ctx.publish_resource(executor, types=[Executor])
    await component.start(ctx)
    ctx.dbsession.execute('CREATE TABLE foo (id INTEGER PRIMARY KEY)')
    ctx.dbsession.execute('INSERT INTO foo (id) VALUES(3)')
    await ctx.finished.dispatch(Exception('dummy') if raise_exception else None,
                                return_future=True)

    rows = ctx.sql.execute('SELECT * FROM foo').fetchall()
    assert len(rows) == (0 if raise_exception else 1)
 async def start(self, ctx: Context):
     for resource_name, context_attr, mailer in self.mailers:
         await mailer.start(ctx)
         ctx.publish_resource(mailer, resource_name, context_attr, types=[Mailer])
         logger.info('Configured mailer (%s / ctx.%s)', resource_name, context_attr)