From f7187beff2d35f5272b859c53d26273601adc5d8 Mon Sep 17 00:00:00 2001 From: aya Date: Wed, 16 Oct 2024 14:32:19 +0300 Subject: [PATCH] adding test for topic content positive scenario --- src/node/store_response.py | 4 ++-- tests/store/test_api_flags.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/node/store_response.py b/src/node/store_response.py index 602ad007..7e168ba5 100644 --- a/src/node/store_response.py +++ b/src/node/store_response.py @@ -59,10 +59,10 @@ class StoreResponse: else: return None - def message_payload(self, index): + def message_content(self, index): try: if self.messages is not None: - payload = self.messages[index]["message"]["payload"] + payload = self.messages[index]["message"]["contentTopic"] return payload else: return None diff --git a/tests/store/test_api_flags.py b/tests/store/test_api_flags.py index a230ab88..674cf19a 100644 --- a/tests/store/test_api_flags.py +++ b/tests/store/test_api_flags.py @@ -1,7 +1,9 @@ import pytest +from time import time from src.libs.custom_logger import get_custom_logger from src.libs.common import to_base64 from src.node.waku_message import WakuMessage +from src.node.store_response import StoreResponse from src.steps.store import StepsStore from src.test_data import SAMPLE_INPUTS from src.test_data import PUBSUB_TOPICS_STORE @@ -76,3 +78,19 @@ class TestApiFlags(StepsStore): except Exception as e: logger.error(f"Topic {wrong_topic} is wrong ''n: {str(e)}") assert e.args[0].find("messages': []") != -1, "Message shall not be stored for wrong topic" + + def test_get_store_messages_with_content_topic(self): + # positive scenario + content_topic = "/myapp/1/latest/protoo" + message = {"payload": to_base64(self.test_payload), "" "contentTopic": content_topic, "timestamp": int(time() * 1e9)} + logger.debug(f"Trying to publish msg with content topic {content_topic}") + msg = self.publish_message(message=message) + store_response = self.get_messages_from_store(self.store_node1, include_data="true", content_topics=content_topic) + try: + if store_response.messages is not None: + stored_contentTopic = store_response.message_content(0) + logger.debug(f"stored content topic is {stored_contentTopic}") + assert stored_contentTopic == content_topic, "content topics don't match" + + except Exception as e: + raise Exception(f"can't get message with content topic {content_topic}")