コード例 #1
0
ファイル: bot_test.py プロジェクト: MrMeta/yui
def test_bot_init(monkeypatch):
    importlib = FakeImportLib()

    monkeypatch.setattr("importlib.import_module", importlib.import_module)

    config = AttrDict(copy.deepcopy(DEFAULT))
    config.DEBUG = True
    config.DATABASE_URL = 'sqlite:///'
    config.MODELS = ['yui.model1', 'yui.model2']
    config.HANDLERS = ['yui.handler1', 'yui.handler2']
    config['LOGGING']['loggers']['yui']['handlers'] = ['console']
    config.REGISTER_CRONTAB = False
    del config['LOGGING']['handlers']['file']
    bot = Bot(config)

    assert bot.config == config
    assert bot.channels == []
    assert bot.ims == []
    assert bot.groups == []
    assert bot.loop is None
    assert bot.restart is False
    assert isinstance(bot.api, SlackAPI)
    assert bot.box is box
    assert isinstance(bot.queue, asyncio.Queue)
    assert importlib.import_queue == [
        'yui.handler1',
        'yui.handler2',
        'yui.model1',
        'yui.model2',
    ]
コード例 #2
0
def fx_engine(request):
    try:
        database_url = request.config.getoption('--database-url')
    except ValueError:
        database_url = None

    config = AttrDict(copy.deepcopy(DEFAULT))
    config.DEBUG = True
    config.DATABASE_URL = database_url
    config.MODELS = []
    config.HANDLERS = []
    config['LOGGING']['loggers']['yui']['handlers'] = ['console']
    config.REGISTER_CRONTAB = False
    del config['LOGGING']['handlers']['file']
    bot = Bot(config)
    engine = bot.config.DATABASE_ENGINE
    try:
        metadata = Base.metadata
        metadata.drop_all(bind=engine)
        metadata.create_all(bind=engine)
        yield engine
        metadata.drop_all(bind=engine)
    finally:
        engine.dispose()