Skip to content
Snippets Groups Projects
Unverified Commit 199509b6 authored by Katleho Madisa's avatar Katleho Madisa
Browse files

SAR-149 Added a test for the parameter validation step.

parent c544e2ff
Branches
Tags
No related merge requests found
......@@ -10,7 +10,7 @@ import concurrent.futures
from unittest.mock import patch, MagicMock
from ska.logging import transaction
from ska.logging.transactions import TransactionIdGenerator
from ska.logging.transactions import TransactionIdGenerator, TransactionParamsError
from tests.conftest import (
get_first_record_and_log_message,
get_last_record_and_log_message,
......@@ -22,15 +22,19 @@ from tests.conftest import (
class TestTransactionIdGeneration:
"""Tests for :class:`~ska.logging.transaction` related to ID generation."""
def test_error_if_params_type_is_not_mapping(self):
parameters = []
with pytest.raises(TransactionParamsError):
with transaction("name", parameters):
pass
def test_preference_order(self, id_generator_stub):
parameters = {
"other": "config",
"transaction_id": "xyz123",
"other_transaction_id_key": "def789",
}
with transaction(
"name", parameters, transaction_id="abc1234"
) as transaction_id:
with transaction("name", parameters, transaction_id="abc1234") as transaction_id:
assert transaction_id == "abc1234"
parameters = {
......@@ -100,9 +104,7 @@ class TestTransactionIdGeneration:
class TestTransactionLogging:
"""Tests for :class:`~ska.logging.transaction` related to logging."""
def test_name_and_id_and_params_in_context_handler(
self, id_generator_stub, recording_logger
):
def test_name_and_id_and_params_in_context_handler(self, id_generator_stub, recording_logger):
parameters = {"other": ["config", 1, 2, 3.0]}
with transaction("name", parameters) as transaction_id:
pass
......@@ -123,9 +125,7 @@ class TestTransactionLogging:
assert "name" in last_log_message
assert transaction_id in last_log_message
def test_exception_logs_transaction_id_and_command(
self, id_generator_stub, recording_logger
):
def test_exception_logs_transaction_id_and_command(self, id_generator_stub, recording_logger):
parameters = {"other": ["config", 1, 2, 3.0]}
with pytest.raises(RuntimeError):
with transaction("name", parameters) as transaction_id:
......@@ -133,16 +133,10 @@ class TestTransactionLogging:
record_logs = get_all_record_logs(recording_logger)
for log_msg in record_logs:
if (
"RuntimeError" in log_msg
and transaction_id in log_msg
and "name" in log_msg
):
if "RuntimeError" in log_msg and transaction_id in log_msg and "name" in log_msg:
return
assert (
0
), f"RuntimeError and transaction tag not found in exception logs: {record_logs}"
assert 0, f"RuntimeError and transaction tag not found in exception logs: {record_logs}"
class TestTransactionIdGenerator:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment