Exemplo n.º 1
0
'''Fixture based DE Server for the de-client tests'''
# pylint: disable=redefined-outer-name

import io
import sys

import pytest

from decisionengine.framework.tests.fixtures import (  # noqa: F401
    PG_DE_DB_WITH_SCHEMA, PG_PROG, DEServer, TEST_CONFIG_PATH,
    TEST_CHANNEL_CONFIG_PATH,
)

deserver = DEServer(conf_path=TEST_CONFIG_PATH,
                    channel_conf_path=TEST_CHANNEL_CONFIG_PATH)  # pylint: disable=invalid-name


@pytest.mark.usefixtures("deserver")
def test_client_status_msg_to_stdout(deserver):
    """Make sure the actuall client console call goes to stdout"""
    import decisionengine.framework.engine.de_client as de_client

    myoutput = io.StringIO()
    sys.stdout = myoutput
    de_client.console_scripts_main([
        '--host', deserver.server_address[0], '--port',
        str(deserver.server_address[1]), '--status'
    ])
    sys.stdout = sys.__stdout__
    assert 'channel: test_channel' in myoutput.getvalue()
Exemplo n.º 2
0
import os
import re

from decisionengine.framework.tests.fixtures import (  # noqa: F401
    DEServer,
    PG_DE_DB_WITHOUT_SCHEMA,
    PG_PROG,
    SQLALCHEMY_PG_WITH_SCHEMA,
    SQLALCHEMY_TEMPFILE_SQLITE,
    TEST_CONFIG_PATH,
)

_channel_config_dir = os.path.join(TEST_CONFIG_PATH, "test-shared-sources-conflicting")  # noqa: F405
deserver_conflicting = DEServer(
    conf_path=TEST_CONFIG_PATH, channel_conf_path=_channel_config_dir
)  # pylint: disable=invalid-name


def record_that_matches(substring, records):
    return any(substring in r.message for r in records)


def test_conflicting_source_configurations(deserver_conflicting, caplog):
    assert record_that_matches(
        "Mismatched configurations for source with name source", caplog.get_records(when="setup")
    )


_channel_config_dir = os.path.join(TEST_CONFIG_PATH, "test-shared-sources")  # noqa: F405
deserver_shared = DEServer(
'''Fixture based DE Server tests of invalid channel configs'''
# pylint: disable=redefined-outer-name

import os
import pytest
import re
from logging import ERROR

from decisionengine.framework.tests.fixtures import DE_DB, DE_HOST, PG_PROG, DEServer, TEST_CONFIG_PATH, TEST_CHANNEL_CONFIG_PATH  # noqa: F401

_channel_config_dir = os.path.join(TEST_CONFIG_PATH,
                                   'test-bad-channel')  # noqa: F405
deserver = DEServer(conf_path=TEST_CONFIG_PATH,
                    channel_conf_path=_channel_config_dir)  # pylint: disable=invalid-name


def _missing_produces(name):
    return f"The following modules are missing '@produces' declarations:\n\n - {name}\n"


def _missing_consumes(name):
    return f"The following modules are missing '@consumes' declarations:\n\n - {name}\n"


def _consumes_not_subset(test_str):
    return "The following products are required but not produced:\n['B']" in test_str


def _expected_circularity(test_str):
    return re.search(
        "Circular dependencies exist among these items: "
Exemplo n.º 4
0
# SPDX-License-Identifier: Apache-2.0
"""Fixture based DE Server tests of adding a channel later on"""
# pylint: disable=redefined-outer-name
import os
import shutil

import pytest

from decisionengine.framework.tests.fixtures import (  # noqa: F401
    DEServer, PG_DE_DB_WITHOUT_SCHEMA, PG_PROG, SQLALCHEMY_PG_WITH_SCHEMA,
    SQLALCHEMY_TEMPFILE_SQLITE, TEST_CHANNEL_CONFIG_PATH, TEST_CONFIG_PATH,
)

deserver = DEServer(
    conf_path=TEST_CONFIG_PATH,
    channel_conf_path=None,
    make_conf_dirs_if_missing=True,
)  # pylint: disable=invalid-name


@pytest.mark.timeout(35)
@pytest.mark.usefixtures("deserver")
def test_client_can_start_one_channel_added_after_startup(deserver):
    """Verify client can start a single channel"""
    output = deserver.de_client_run_cli("--status")
    assert "No channels are currently active." in output
    output = deserver.de_client_run_cli("--show-channel-config",
                                        "test_channel")
    assert "There is no active channel named test_channel." in output

    channel_config = os.path.join(TEST_CHANNEL_CONFIG_PATH,