Skip to content

Commit

Permalink
Self Ref parses command (#455)
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBurchLog authored Mar 1, 2024
1 parent 332edbf commit 1ac3ca1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 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.2
------
TBD

- Fixed bug where Self Referencing SystemClients did not inspect the command properly for default parameters

3.24.1
------
2/28/2024
Expand Down
13 changes: 7 additions & 6 deletions brewtils/request_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import six
from requests import ConnectionError as RequestsConnectionError

from brewtils.decorators import _parse_method
import brewtils.plugin
from brewtils.errors import (
BGGivesUpError,
Expand Down Expand Up @@ -63,12 +64,12 @@ def process_command(self, request):
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.default:
if parameter.key not in request.parameters:
request.parameters[parameter.key] = parameter.default
command = _parse_method(getattr(brewtils.plugin.CLIENT, request.command, None))
if command:
for parameter in command.parameters:
if parameter.default:
if parameter.key not in request.parameters:
request.parameters[parameter.key] = parameter.default

request.status = "IN_PROGRESS"

Expand Down
21 changes: 4 additions & 17 deletions test/request_handling_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from mock import ANY, MagicMock, Mock
from requests import ConnectionError as RequestsConnectionError

from brewtils.decorators import parameter
import brewtils.plugin
from brewtils.errors import (
DiscardMessageException,
Expand Down Expand Up @@ -525,24 +526,12 @@ def command_one(self):
def command_two(self):
return False

@parameter(key="key", default="value", is_kwarg=True)
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"),
Command(
name="command_three",
parameters=[Parameter(is_kwarg=True, key="key", default="value")],
),
]
)

@pytest.fixture
def resolver_mock(self):
def resolve(values, **_):
Expand All @@ -554,7 +543,7 @@ def resolve(values, **_):
return resolver

@pytest.fixture
def local_request_processor(self, system_client, client, resolver_mock):
def local_request_processor(self, client, resolver_mock):
brewtils.plugin.CLIENT = client

def return_input_side_effect(*args, **kwargs):
Expand All @@ -563,9 +552,7 @@ def return_input_side_effect(*args, **kwargs):
_ez_client = Mock()
_ez_client.put_request.side_effect = return_input_side_effect

return LocalRequestProcessor(
system=system_client, easy_client=_ez_client, resolver=resolver_mock
)
return LocalRequestProcessor(easy_client=_ez_client, resolver=resolver_mock)

def setup_request_context(self):
brewtils.plugin.request_context = threading.local()
Expand Down

0 comments on commit 1ac3ca1

Please sign in to comment.