Skip to content

Commit 0be033c

Browse files
committed
Fixed a bug wherein ActionResponse.action was not being set upon initialization.
Summary: - Fixed a bug wherein ActionResponse.action was not being set upon initialization. - Add a test for this behavior. Test Plan: Ran the test suite locally to ensure everything worked. Reviewers: #foundry, ashfall, bgreenberg Reviewed By: #foundry, ashfall, bgreenberg Subscribers: ashfall, jenkinsbot, michaelmanganiello Differential Revision: https://phabricator.evbhome.com/D32595
1 parent 75f4582 commit 0be033c

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

‎pysoa/server/action.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ def __call__(self, action_request):
6565
raise ResponseValidationError(action=action_request.action, errors=errors)
6666
# Make an ActionResponse and return it
6767
if response_body is not None:
68-
return ActionResponse(body=response_body)
68+
return ActionResponse(
69+
action=action_request.action,
70+
body=response_body,
71+
)
6972
else:
70-
return ActionResponse()
73+
return ActionResponse(action=action_request.action)

‎pysoa/server/server.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ def process_request(self, job_request):
112112
# Run action
113113
action = self.action_class_map[action_request.action](self.settings)
114114
action_response = action(action_request)
115-
action_response.action = action_request.action
116115

117116
# Run process ActionResponse middleware
118117
for middleware in self.middleware:

‎tests/server_tests/test_actions.py‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from conformity import fields
22

3-
from pysoa.common.types import ActionRequest
3+
from pysoa.common.types import (
4+
ActionRequest,
5+
ActionResponse,
6+
)
47
from pysoa.server.action import Action
58
from pysoa.server.errors import ActionError
69

@@ -12,6 +15,9 @@ class TestAction(Action):
1215
'string_field': fields.UnicodeString(),
1316
})
1417

18+
def run(self, request):
19+
pass
20+
1521

1622
class TestActionValidation(object):
1723
def setup_method(self, method):
@@ -31,13 +37,13 @@ def test_validate_without_request_schema(self):
3137
}
3238

3339
try:
34-
self.action.validate(self.action_request)
40+
self.action(self.action_request)
3541
except ActionError:
3642
pytest.fail('An unexpected ActionError was raised.')
3743

3844
def test_validate_without_request_errors(self):
3945
try:
40-
self.action.validate(self.action_request)
46+
self.action(self.action_request)
4147
except ActionError:
4248
pytest.fail('An unexpected ActionError was raised.')
4349

@@ -51,3 +57,8 @@ def test_validate_with_request_errors(self):
5157

5258
assert len(e.value.errors) == 1
5359
assert e.value.errors[0].field == u'string_field'
60+
61+
def test_returns_action_response(self):
62+
response = self.action(self.action_request)
63+
assert isinstance(response, ActionResponse)
64+
assert response.action == self.action_request.action

0 commit comments

Comments
 (0)