def test_plugin_import_error(loop): bot = sirbot.SirBot(loop=loop) bot.config['sirbot'] = { 'plugins': ['xxx', ] } with pytest.raises(ImportError): bot._import_plugins()
def test_load_config(loop): config = { 'sirbot': { 'plugins': ['tests.core.test_plugin'] } } bot = sirbot.SirBot(loop=loop, config=config) assert bot.config == config
def test_plugin_priority(loop, registry): config = deepcopy(CONFIG) config['test']['priority'] = 80 config['test-error'] = {'priority': 70} config['sirbot']['plugins'].append('tests.core.test_plugin.sirbot_start_error') bot = sirbot.SirBot(loop=loop, config=config) assert bot._start_priority[80] == ['test'] assert bot._start_priority[70] == ['test-error']
def test_get_facade(loop): bot = sirbot.SirBot(loop=loop, config=config) facade = MainFacade(bot._facades) f = facade.get('test') assert isinstance(f, FacadeTest) with pytest.raises(FacadeNotAvailable) as error: facade.get('foo') assert error.value.facade == 'foo'
def test_middleware(loop, test_client): async def handler(request): assert isinstance(request['facades'], MainFacade) return Response(text='test') bot = sirbot.SirBot(loop=loop, config=CONFIG) bot._app.router.add_route('GET', '/', handler) server = loop.run_until_complete(test_client(bot._app)) rep = loop.run_until_complete(server.get('/')) assert 200 == rep.status assert 'test' == (loop.run_until_complete(rep.text()))
def test_logging_config(loop): config = { 'logging': { 'version': 1, 'loggers': { 'sirbot.core': { 'level': 'WARNING' }, 'sirbot': { 'level': 'ERROR' } } }, 'sirbot': { 'plugins': ['tests.core.test_plugin.sirbot'] } } bot = sirbot.SirBot(loop=loop, config=config) assert logging.getLogger('sirbot.core').level == 30 assert logging.getLogger('sirbot').level == 40
def test_main_facade(loop): bot = sirbot.SirBot(loop=loop, config=config) facade = MainFacade(bot._facades) second_facade = facade.new() assert isinstance(second_facade, MainFacade) assert type(facade) == type(second_facade)
def test_facade_is_correct_function(loop): bot = sirbot.SirBot(loop=loop, config=config) assert isinstance(bot._facades.get('test').__self__, PluginTest) assert bot._facades.get( 'test').__qualname__ == PluginTest.facade.__qualname__
def test_register_facade(loop): bot = sirbot.SirBot(loop=loop, config=config) assert 'test' in bot._facades
def test_plugin_task_error(loop, test_server, capsys): config = deepcopy(CONFIG) config['sirbot']['plugins'] = ['tests.core.test_plugin.sirbot_start_error'] bot = sirbot.SirBot(loop=loop, config=config) with pytest.raises(ValueError): loop.run_until_complete(test_server(bot._app))
def test_start_plugins(loop, test_server): bot = sirbot.SirBot(loop=loop, config=CONFIG) loop.run_until_complete(test_server(bot._app)) assert 'test' in bot._tasks
def test_contains_facade(loop): bot = sirbot.SirBot(loop=loop, config=config) facade = MainFacade(bot._facades) assert 'test' in facade assert 'foo' not in facade
def test_plugin_import(loop, test_server): bot = sirbot.SirBot(loop=loop, config=CONFIG) loop.run_until_complete(test_server(bot._app)) assert bot._pm.has_plugin('tests.core.test_plugin.sirbot')
def test_bot_is_starting(loop, test_server): bot = sirbot.SirBot(loop=loop) loop.run_until_complete(test_server(bot._app)) assert bot._app == bot.app
def test_plugin_no_start(loop, test_server): config = deepcopy(CONFIG) config['test']['priority'] = False bot = sirbot.SirBot(loop=loop, config=config) assert bot._start_priority == {} assert bot._plugins == {}
def test_getitem_facade(loop): bot = sirbot.SirBot(loop=loop, config=config) facade = MainFacade(bot._facades) assert isinstance(facade['test'], FacadeTest) with pytest.raises(KeyError): _ = facade['foo']
def test_initialize_plugins(loop): bot = sirbot.SirBot(loop=loop, config=CONFIG) assert isinstance(bot._plugins['test']['plugin'], PluginTest)
def test_len_facade(loop): bot = sirbot.SirBot(loop=loop, config=config) facade = MainFacade(bot._facades) assert len(facade) == 1
def test_plugin_configure(loop, test_server): bot = sirbot.SirBot(loop=loop, config=CONFIG) loop.run_until_complete(bot._configure_plugins()) assert bot._plugins['test']['plugin'].config == CONFIG['test']