Source

araldo / test / plugins_test.py

Full commit
import pytest
from araldo import plugins as sut
from araldo.config import Config


@pytest.fixture
def conf1_name():
    return "testfiles/conf1.yaml"


@pytest.fixture
def plugin_manager(conf1_name):
    config = Config.create(conf1_name)
    return sut.PluginManager.create(config)


def test_load_plugins_new(plugin_manager):
    plugin_manager._plugins = None
    plugin_manager.load_plugins()
    assert plugin_manager._plugins is not None


def test_load_plugins_only_creates_once(plugin_manager):
    plugin_manager._plugins = None
    plugin_manager.load_plugins()
    assert plugin_manager._plugins is not None
    plugins1 = plugin_manager._plugins
    plugin_manager.load_plugins()
    plugins2 = plugin_manager._plugins
    assert id(plugins1) == id(plugins2)


#def test_instantiate_plugins(conf1_name):
#    sut.PluginManager.instantiate_plugins()


def test_remove_existing_plugin_instance(plugin_manager):
    plugin_manager.remove_plugin_instance(
        "araldo.endpoints.outbound",
        "redis_out_3")
    assert "redis_out_3" not in \
        plugin_manager._plugin_instances["araldo.endpoints.outbound"]


def test_remove_nonexisting_plugin_instance(plugin_manager):
    assert "redis_out_XX" not in \
        plugin_manager._plugin_instances["araldo.endpoints.outbound"]
    plugin_manager.remove_plugin_instance(
        "araldo.endpoints.outbound",
        "redis_out_XX")
    assert "redis_out_XX" not in \
        plugin_manager._plugin_instances["araldo.endpoints.outbound"]


def test_error_if_singleton_not_initialized():
    sut.PluginManager._instance = None
    with pytest.raises(Exception):
        sut.PluginManager.get()