Source

araldo / test / server_test.py

""" Tests for module araldo.server
"""

import pytest
from mock import Mock, patch
from araldo.server import (
    start_server, setup_logging, setup_sending,
    setup_signals, sig_handler, setup_plugins)
from gevent.queue import Queue
from araldo import server
from araldo.plugins import PluginManager
from araldo.config import Config


@pytest.fixture
def queue():
    return Queue()


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


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


def test_server(plugin_manager, queue):
    start_mock = Mock()
    start_server(9000, queue, start_mock)
    assert start_mock.called


def test_setup_logging():
    logger = setup_logging()
    assert len(logger.handlers) > 0


def test_setup_sending(queue, plugin_manager):
    config = Config.get()
    config.settings()["routes"] = {}
    setup_sending(config, queue)


def test_setup_signals():
    with patch.object(server.signal, "signal"):
        setup_signals()


def test_setup_plugins(conf1_name):
    config = Config(conf1_name)
    logger = Mock()
    setup_plugins(logger, config)


def test_sig_handler():
    with patch.object(server.sys, "exit") as ex:
        sig_handler(None, None)
        assert ex.called