Source

araldo / test / plugin_manager_test.py

Full commit
import pytest
from araldo import plugin_manager 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(config)


def test_plugin_subconfig(plugin_manager):
    sub_config = plugin_manager.plugin_subconfig(
        "araldo.endpoints.endpoint", "mock_1")
    assert sub_config == {
        'channel': 'channel_1',
        'id': 'endpoint-mock',
        'name': 'mock_1'}


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_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"]