From a68992195ae346dee49d144d619cc68fea1564cb Mon Sep 17 00:00:00 2001 From: TheBurchLog <5104941+TheBurchLog@users.noreply.github.com> Date: Mon, 26 Feb 2024 07:59:58 -0500 Subject: [PATCH] Self Ref Kwargs support (#452) --- CHANGELOG.rst | 6 ++++++ brewtils/request_handling.py | 8 ++++++++ test/request_handling_test.py | 21 +++++++++++++++++++-- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index f349a22b..67960972 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,6 +1,12 @@ Brewtils Changelog ================== +3.24.1 +------ +TBD + +- Self Referecing SystemClient now supports kwargs provided through the Parameter annotation + 3.24.0 ------ 2/13/2024 diff --git a/brewtils/request_handling.py b/brewtils/request_handling.py index 80d01b4a..68f52f72 100644 --- a/brewtils/request_handling.py +++ b/brewtils/request_handling.py @@ -62,6 +62,14 @@ def process_command(self, request): request.parent = Request(id=str(parent_request.id)) request.has_parent = True + # check for kwargs on the target command + for command in self._system.commands: + if command.name == request.command: + for parameter in command.parameters: + if parameter.is_kwarg: + if parameter.key not in request.parameters: + request.parameters[parameter.key] = parameter.default + request.status = "IN_PROGRESS" request = self._ez_client.put_request(request) diff --git a/test/request_handling_test.py b/test/request_handling_test.py index bb97724d..8d935281 100644 --- a/test/request_handling_test.py +++ b/test/request_handling_test.py @@ -22,7 +22,7 @@ SuppressStacktrace, TooLargeError, ) -from brewtils.models import Command, Request, System +from brewtils.models import Command, Request, System, Parameter from brewtils.request_handling import ( HTTPRequestUpdater, LocalRequestProcessor, @@ -525,12 +525,22 @@ def command_one(self): def command_two(self): return False + def command_three(self, **kwargs): + return kwargs + return ClientTest() @pytest.fixture def system_client(self): return System( - commands=[Command(name="command_one"), Command(name="command_two")] + commands=[ + Command(name="command_one"), + Command(name="command_two"), + Command( + name="command_three", + parameters=[Parameter(is_kwarg=True, key="key", default="value")], + ), + ] ) @pytest.fixture @@ -578,3 +588,10 @@ def test_process_command(self, local_request_processor): ).output == "false" ) + + assert ( + local_request_processor.process_command( + Request(command="command_three", parameters={}) + ).output + == '{"key": "value"}' + )