Skip to content

Commit

Permalink
Fixed a bug wherein ActionResponse.action was not being set upon init…
Browse files Browse the repository at this point in the history
…ialization.

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
  • Loading branch information
sethbrite committed Mar 23, 2017
1 parent 75f4582 commit 0be033c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
7 changes: 5 additions & 2 deletions pysoa/server/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ def __call__(self, action_request):
raise ResponseValidationError(action=action_request.action, errors=errors)
# Make an ActionResponse and return it
if response_body is not None:
return ActionResponse(body=response_body)
return ActionResponse(
action=action_request.action,
body=response_body,
)
else:
return ActionResponse()
return ActionResponse(action=action_request.action)
1 change: 0 additions & 1 deletion pysoa/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def process_request(self, job_request):
# Run action
action = self.action_class_map[action_request.action](self.settings)
action_response = action(action_request)
action_response.action = action_request.action

# Run process ActionResponse middleware
for middleware in self.middleware:
Expand Down
17 changes: 14 additions & 3 deletions tests/server_tests/test_actions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from conformity import fields

from pysoa.common.types import ActionRequest
from pysoa.common.types import (
ActionRequest,
ActionResponse,
)
from pysoa.server.action import Action
from pysoa.server.errors import ActionError

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

def run(self, request):
pass


class TestActionValidation(object):
def setup_method(self, method):
Expand All @@ -31,13 +37,13 @@ def test_validate_without_request_schema(self):
}

try:
self.action.validate(self.action_request)
self.action(self.action_request)
except ActionError:
pytest.fail('An unexpected ActionError was raised.')

def test_validate_without_request_errors(self):
try:
self.action.validate(self.action_request)
self.action(self.action_request)
except ActionError:
pytest.fail('An unexpected ActionError was raised.')

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

assert len(e.value.errors) == 1
assert e.value.errors[0].field == u'string_field'

def test_returns_action_response(self):
response = self.action(self.action_request)
assert isinstance(response, ActionResponse)
assert response.action == self.action_request.action

0 comments on commit 0be033c

Please sign in to comment.