From df37f093d3020cfd598f17aa9197d7ddcc16cf94 Mon Sep 17 00:00:00 2001 From: chausman <chausman@nrao.edu> Date: Thu, 6 Jun 2024 10:57:10 -0600 Subject: [PATCH] include messenger tests --- .gitlab-ci.yml | 8 +++++ ci/unit-test.template.yml | 12 +++++--- .../test_get_archive_ingestion_message.py | 1 - shared/messaging/test/test_messenger.py | 1 - shared/messaging/test/test_router.py | 30 +------------------ 5 files changed, 17 insertions(+), 35 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 524227c83..000319c05 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -248,6 +248,14 @@ unit test notification: TEST_PREFIX2: "shared/workspaces/test/" extends: .unit-test +unit test messaging: + interruptible: true + stage: unit-test + variables: + SERVICE_NAME: "messaging" + PATH_PREFIX: "shared/" + extends: .unit-test + ############################################### # Create Coverage Report diff --git a/ci/unit-test.template.yml b/ci/unit-test.template.yml index 7701f14ae..78d6d3074 100644 --- a/ci/unit-test.template.yml +++ b/ci/unit-test.template.yml @@ -5,10 +5,14 @@ - cd ${PATH_PREFIX}${SERVICE_NAME} # use the poetry virtual environment and packages - poetry install --with test - - pwd - - $(poetry env info -p)/bin/pytest . --junitxml=tests-service.xml --cov=${SERVICE_NAME} --cov-report= - - $(poetry env info -p)/bin/pytest ../../${TEST_PREFIX2}${SERVICE_NAME} --junitxml=tests-shared.xml --cov=../../${PATH_PREFIX2}${SERVICE_NAME} --cov-append --cov-report= - - $(poetry env info -p)/bin/junitparser merge tests-service.xml tests-shared.xml tests.xml + - | + if [ -z "${PATH_PREFIX2+x}" ]; then + $(poetry env info -p)/bin/pytest . --junitxml=tests.xml --cov=${SERVICE_NAME} --cov-report= + else + $(poetry env info -p)/bin/pytest . --junitxml=tests-service.xml --cov=${SERVICE_NAME} --cov-report= + $(poetry env info -p)/bin/pytest ../../${TEST_PREFIX2}${SERVICE_NAME} --junitxml=tests-shared.xml --cov=../../${PATH_PREFIX2}${SERVICE_NAME} --cov-append --cov-report= + $(poetry env info -p)/bin/junitparser merge tests-service.xml tests-shared.xml tests.xml + fi - mv ./.coverage ${CI_PROJECT_DIR}/.coverage.${SERVICE_NAME}.${CI_COMMIT_SHORT_SHA} - mv ./tests.xml ${CI_PROJECT_DIR}/tests.${SERVICE_NAME}.${CI_COMMIT_SHORT_SHA}.xml artifacts: diff --git a/shared/messaging/test/test_get_archive_ingestion_message.py b/shared/messaging/test/test_get_archive_ingestion_message.py index b2ba2c987..8e7e0bb9c 100644 --- a/shared/messaging/test/test_get_archive_ingestion_message.py +++ b/shared/messaging/test/test_get_archive_ingestion_message.py @@ -25,7 +25,6 @@ from enum import Enum from pprint import pprint from typing import Dict -import pytest from _pytest.capture import CaptureFixture from _pytest.logging import LogCaptureFixture from messaging.router import Router diff --git a/shared/messaging/test/test_messenger.py b/shared/messaging/test/test_messenger.py index daaf54904..681d0a46c 100644 --- a/shared/messaging/test/test_messenger.py +++ b/shared/messaging/test/test_messenger.py @@ -22,7 +22,6 @@ import logging import sys from unittest.mock import MagicMock, patch -import pytest from kombu import Exchange, Queue from messaging.messenger import AMQPServerInitializer diff --git a/shared/messaging/test/test_router.py b/shared/messaging/test/test_router.py index 9769f8710..3c7ae846e 100644 --- a/shared/messaging/test/test_router.py +++ b/shared/messaging/test/test_router.py @@ -27,37 +27,9 @@ from unittest.mock import MagicMock, patch import pytest from _pytest.capture import CaptureFixture -from messaging.messenger import SenderIF from messaging.router import Router, on_message - -class MockMessageSender(SenderIF): - """Pretends to send a message""" - - destination = None - - def send_message(self, **message): - """ - Don't send this message, but play it on TV - - :param message: message to send as Dict - :return: - """ - print(f"sending message: {message}") - self.destination.receive_message(json.dumps(message)) - - -@pytest.fixture(scope="module") -def test_router() -> Router: - """ - Pytest fixture providing a Router class for testing - - :return: Test Router - """ - messenger = MockMessageSender() - router = Router("test", messenger) - messenger.destination = router - return router +from .conftest import test_router logger = logging.getLogger("router") -- GitLab