async def test_resources(): mailer = SMTPMailer(tls_context='contextresource') context = Context() sslcontext = ssl.create_default_context() context.add_resource(sslcontext, 'contextresource') await mailer.start(context) assert mailer.tls_context is sslcontext
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') engine = create_engine('sqlite:///%s' % db_path, poolclass=NullPool) engine.execute('CREATE TABLE foo (id INTEGER PRIMARY KEY)') component = SQLAlchemyComponent( url={'drivername': 'sqlite', 'database': str(db_path)}, commit_executor=executor if commit_executor == 'instance' else commit_executor) ctx = Context() ctx.add_resource(executor, types=[Executor]) await component.start(ctx) ctx.sql.execute('INSERT INTO foo (id) VALUES(3)') await ctx.close(Exception('dummy') if raise_exception else None) rows = engine.execute('SELECT * FROM foo').fetchall() assert len(rows) == (0 if raise_exception else 1)