Skip to content
Snippets Groups Projects
Commit 20a5595d authored by Philipp S. Sommer's avatar Philipp S. Sommer
Browse files

Merge branch 'send-request-json' into 'master'

make send-request and compute accept plain json

See merge request !74
parents 6b05872a 1ed74a5c
No related branches found
No related tags found
1 merge request!74make send-request and compute accept plain json
Pipeline #499426 passed
......@@ -479,12 +479,15 @@ 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.",
type=argparse.FileType("r"),
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,8 +498,11 @@ def get_parser(
)
sp.add_argument(
"request",
help="A JSON-formatted file with the request.",
type=argparse.FileType("r"),
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"])
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment