From dd65e4f32fae31ebfb4954e8d921eeb378a5bee7 Mon Sep 17 00:00:00 2001
From: Philipp Sommer <philipp.sommer@hereon.de>
Date: Thu, 27 Feb 2025 20:16:23 +0100
Subject: [PATCH 1/2] make send-request and compute accept plain json

---
 demessaging/cli.py           |  4 ++--
 tests/test_backend_module.py | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/demessaging/cli.py b/demessaging/cli.py
index 3944106..cd81acb 100644
--- a/demessaging/cli.py
+++ b/demessaging/cli.py
@@ -484,7 +484,7 @@ def get_parser(
     sp.add_argument(
         "request",
         help="A JSON-formatted file with the request.",
-        type=argparse.FileType("r"),
+        type=_load_dict,
     )
     sp.set_defaults(method_name="send_request", command_params=["request"])
 
@@ -496,7 +496,7 @@ def get_parser(
     sp.add_argument(
         "request",
         help="A JSON-formatted file with the request.",
-        type=argparse.FileType("r"),
+        type=_load_dict,
     )
     sp.set_defaults(method_name="process_request", command_params=["request"])
 
diff --git a/tests/test_backend_module.py b/tests/test_backend_module.py
index b44a48e..68cee9e 100644
--- a/tests/test_backend_module.py
+++ b/tests/test_backend_module.py
@@ -6,6 +6,7 @@
 """Test module for the :mod:`demessaging.backend` module."""
 import importlib
 import inspect
+import json
 import pathlib
 import subprocess as spr
 from textwrap import dedent
@@ -150,6 +151,22 @@ class TestModuleModel:
         test_request = get_request_path("test_request")
         test_dasf_request(random_topic, modpath, test_request)
 
+    def test_request_json(
+        self,
+        random_topic: str,
+        connect_module: Callable[[str, str], spr.Popen],
+        get_test_module_path: Callable[[str], str],
+        get_module_command: Callable[[str, str], List[str]],
+    ) -> None:
+        """Test parsing a request via the pulsar messaging system."""
+        modpath = get_test_module_path("_test_module")
+        connect_module(random_topic, modpath)
+        command = get_module_command(random_topic, modpath)
+        spr.check_call(
+            command
+            + ["send-request", json.dumps({"func_name": "func_basic", "a": 1})]
+        )
+
     def test_request_dump_to(
         self,
         random_topic: str,
@@ -245,6 +262,21 @@ class TestModuleModel:
         response = spr.check_output(command + ["compute", test_request])
         assert response.decode("utf-8").strip() == "[1]"
 
+    def test_cli_compute_json(
+        self,
+        random_topic: str,
+        get_test_module_path: Callable[[str], str],
+        get_module_command: Callable[[str, str], List[str]],
+    ) -> None:
+        """Test running the compute cli command."""
+        modpath = get_test_module_path("_test_module")
+        command = get_module_command(random_topic, modpath)  # type: ignore[call-arg]
+        response = spr.check_output(
+            command
+            + ["compute", json.dumps({"func_name": "func_basic", "a": 1})]
+        )
+        assert response.decode("utf-8").strip() == "[1]"
+
     def test_request_arbitrary(
         self,
         random_topic: str,
-- 
GitLab


From 1ed74a5c291a88926164fbfabf2d1e23c9468344 Mon Sep 17 00:00:00 2001
From: Philipp Sommer <philipp.sommer@hereon.de>
Date: Thu, 27 Feb 2025 20:19:32 +0100
Subject: [PATCH 2/2] update docs

---
 demessaging/cli.py | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/demessaging/cli.py b/demessaging/cli.py
index cd81acb..f28eafe 100644
--- a/demessaging/cli.py
+++ b/demessaging/cli.py
@@ -479,11 +479,14 @@ def get_parser(
     # test subparser (to test the connection to the connect to the pulsar
     # messaging system)
     sp = subparsers.add_parser(
-        "send-request", help="Test a request via the pulsar messaging system."
+        "send-request", help="Test a request via the messaging system."
     )
     sp.add_argument(
         "request",
-        help="A JSON-formatted file with the request.",
+        help=(
+            "The request to send as YAML string, or the path to a YAML or "
+            "JSON file."
+        ),
         type=_load_dict,
     )
     sp.set_defaults(method_name="send_request", command_params=["request"])
@@ -495,7 +498,10 @@ def get_parser(
     )
     sp.add_argument(
         "request",
-        help="A JSON-formatted file with the request.",
+        help=(
+            "The request to process as YAML string, or the path to a YAML or "
+            "JSON file."
+        ),
         type=_load_dict,
     )
     sp.set_defaults(method_name="process_request", command_params=["request"])
-- 
GitLab