Add unit test for wrappers

This commit is contained in:
Aya Hassan 2026-03-10 18:59:54 +01:00
parent b5ef345ea6
commit 437b7fc9c7
3 changed files with 79 additions and 0 deletions

View File

@ -47,3 +47,29 @@ def wrapper_unsubscribe(node, content_topic, timeout_s=20.0):
content_topic=content_topic,
timeout_s=timeout_s,
)
def wrapper_send_message(node, message, timeout_s=20.0):
return node.send_message(
message=message,
timeout_s=timeout_s,
)
def wrapper_get_available_node_info_ids(node, timeout_s=20.0):
return node.get_available_node_info_ids(
timeout_s=timeout_s,
)
def wrapper_get_node_info(node, node_info_id, timeout_s=20.0):
return node.get_node_info(
node_info_id=node_info_id,
timeout_s=timeout_s,
)
def wrapper_get_available_configs(node, timeout_s=20.0):
return node.get_available_configs(
timeout_s=timeout_s,
)

View File

@ -0,0 +1,18 @@
class NodeStub:
def send_message(self, message, timeout_s=20.0):
self.message = message
self.timeout_s = timeout_s
return Ok(1)
def get_available_node_info_ids(self, timeout_s=20.0):
self.timeout_s = timeout_s
return Ok(2)
def get_node_info(self, node_info_id, timeout_s=20.0):
self.node_info_id = node_info_id
self.timeout_s = timeout_s
return Ok(3)
def get_available_configs(self, timeout_s=20.0):
self.timeout_s = timeout_s
return Ok(4)

View File

@ -0,0 +1,35 @@
import inspect
import pytest
from result import Ok
from src.libs.custom_logger import get_custom_logger
from src.steps.wrappers_setup import NodeStub
from src.node import wrappers_manager
# from wrapper_setup import NodeWrapper
logger = get_custom_logger(__name__)
class TestWrappersManager:
@pytest.fixture(scope="function", autouse=True)
def wrapper_setup(self):
logger.debug(f"Running setup")
self.node = NodeForTest()
def test_wrapper_send_message(self):
message = {
"contentTopic": "/test/1/chat/proto",
"payload": "SGVsbG8=",
"ephemeral": False,
}
result = wrappers_manager.wrapper_send_message(self.node, message, timeout_s=5.0)
assert result == Ok(1)
assert self.node.last_message == message
assert self.node.last_timeout == 5.0
def test_wrapper_get_available_node_info_ids(self):
result = wrappers_manager.wrapper_get_available_node_info_ids(self.node, timeout_s=6.0)
assert result == Ok(2)