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