def test_reload(mocker): mocker.patch('temboardagent.cli.Application.read_file', autospec=True) mocker.patch('temboardagent.cli.Application.apply_config', autospec=True) from temboardagent.cli import Application app = Application() app.config = mocker.Mock(name='config') app.reload()
def test_fetch_missing(mocker): iter_ep = mocker.patch('temboardagent.cli.iter_entry_points') from temboardagent.cli import Application, UserError app = Application() iter_ep.return_value = [] with pytest.raises(UserError): app.fetch_plugin('myplugin')
def test_fetch_failing(mocker): iter_ep = mocker.patch('temboardagent.cli.iter_entry_points') from temboardagent.cli import Application, UserError app = Application() ep = mocker.Mock(name='ep') ep.load.side_effect = Exception('Pouet') iter_ep.return_value = [ep] with pytest.raises(UserError): app.fetch_plugin('myplugin')
def test_fetch_plugin(mocker): iter_ep = mocker.patch('temboardagent.cli.iter_entry_points') from temboardagent.cli import Application app = Application() ep = mocker.Mock(name='found') ep.name = 'found' ep.load.return_value = 'PLUGIN OBJECT' iter_ep.return_value = [ep] assert 'PLUGIN OBJECT' == app.fetch_plugin(['found'])
def test_bootstrap(mocker): mocker.patch('temboardagent.cli.Application.read_file', autospec=True) mocker.patch('temboardagent.cli.Application.apply_config', autospec=True) mocker.patch('temboardagent.cli.MergedConfiguration') from temboardagent.cli import Application, bootstrap app = Application() app.config.temboard.configfile = 'pouet' app.bootstrap(args=None, environ={}) assert repr(app) app = bootstrap(args=None, environ={}) assert app.apply_config.called is True
def test_update_plugins(mocker): from temboardagent.cli import Application app = Application() unloadme = mocker.Mock(name='unloadme') old_plugins = dict(unloadme=unloadme) loadme = mocker.Mock(name='loadme') app.plugins = dict(loadme=loadme) app.update_plugins(old_plugins=old_plugins) assert loadme.load.called is True assert unloadme.unload.called is True
def test_create_plugins(mocker): mocker.patch( 'temboardagent.cli.Application.fetch_plugin', autospec=True) llp = mocker.patch('temboardagent.cli.load_legacy_plugins', autospec=True) from temboardagent.cli import Application app = Application() app.config = mocker.Mock(name='config') app.config.temboard.plugins = ['legacy', 'ng'] llp.return_value = dict(legacy=dict()) app.create_plugins() assert 'legacy' not in app.plugins assert 'legacy' in app.config.plugins assert 'ng' in app.plugins assert 'ng' not in app.config.plugins
def test_app_pickle(): from pickle import dumps as pickle, loads as unpickle from temboardagent.cli import Application empty_generator = (x for x in []) orig = Application(specs=empty_generator) orig.config.update(dict(a=1)) copy = unpickle(pickle(orig)) assert [] == copy.specs assert copy.config
def test_application_specs(): from temboardagent.cli import Application app = Application() list(app.bootstrap_specs()) list(app.core_specs()) app = Application(with_plugins=None) specs = [str(s) for s in app.core_specs()] assert 'temboard_plugins' not in specs
def test_purge_plugins(): from temboardagent.cli import Application, MergedConfiguration app = Application() app.plugins = dict(destroyme=1, keepme=1) app.config = MergedConfiguration() app.config.update(dict(temboard=dict(plugins=['keepme']))) app.purge_plugins() assert 'destroyme' not in app.plugins
def test_read_file(mocker): from temboardagent.cli import Application, UserError app = Application() open_ = mocker.patch('temboardagent.cli.open', create=True) app.read_file(mocker.Mock(name='parser'), 'pouet.conf') open_.side_effect = IOError() with pytest.raises(UserError): app.read_file(mocker.Mock(name='parser'), 'pouet.conf')
def test_apply_config_without_plugins(mocker): mod = 'temboardagent.cli.' mocker.patch(mod + 'Postgres', autospec=True) mocker.patch(mod + 'Application.setup_logging', autospec=True) from temboardagent.cli import Application app = Application(with_plugins=False) app.config_sources = dict() app.config = mocker.Mock(name='config') app.config.postgresql = dict() app.apply_config() assert app.postgres assert app.setup_logging.called is True
def _test_apply_config_with_plugins(mocker): mod = 'temboardagent.cli.' mocker.patch(mod + 'Postgres', autospec=True) mocker.patch(mod + 'Application.setup_logging', autospec=True) cp = mocker.patch(mod + 'Application.create_plugins', autospec=True) mocker.patch(mod + 'Application.update_plugins', autospec=True) mocker.patch(mod + 'Application.purge_plugins', autospec=True) from temboardagent.cli import Application app = Application() app.config_sources = dict() app.config = mocker.Mock(name='config') app.config.postgresql = dict() cp.return_value = ['plugin'] app.apply_config() assert app.postgres assert app.setup_logging.called is True assert app.update_plugins.called is True assert app.purge_plugins.called is True
from temboardagent.errors import UserError from temboardagent.cli import Application from temboardagent.scheduler import taskmanager from temboardagent.scripts.agent import WorkerPoolService from temboardagent.scripts.agent import SchedulerService from temboardagent.configuration import MergedConfiguration from temboardagent.routing import Router import pgbadger import pytest empty_app = Application() empty_app.config = MergedConfiguration() task_queue = taskmanager.Queue() event_queue = taskmanager.Queue() empty_app.worker_pool = WorkerPoolService(app=empty_app, name=u'worker pool', task_queue=task_queue, event_queue=event_queue) empty_app.scheduler = SchedulerService(app=empty_app, name=u'worker pool', task_queue=task_queue, event_queue=event_queue) empty_app.router = Router()