Skip to content

Commit

Permalink
Self Ref Kwargs support (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBurchLog authored Feb 26, 2024
1 parent ab26102 commit a689921
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions brewtils/request_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
21 changes: 19 additions & 2 deletions test/request_handling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"}'
)

0 comments on commit a689921

Please sign in to comment.