From 0be033c8ee121132a49f59b9f3dcdc442533b722 Mon Sep 17 00:00:00 2001 From: Seth Elliott Date: Thu, 23 Mar 2017 17:38:47 -0500 Subject: [PATCH] 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 --- pysoa/server/action.py | 7 +++++-- pysoa/server/server.py | 1 - tests/server_tests/test_actions.py | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/pysoa/server/action.py b/pysoa/server/action.py index 40b02d8f..97c6483e 100644 --- a/pysoa/server/action.py +++ b/pysoa/server/action.py @@ -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) diff --git a/pysoa/server/server.py b/pysoa/server/server.py index 78776943..e9ee622d 100644 --- a/pysoa/server/server.py +++ b/pysoa/server/server.py @@ -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: diff --git a/tests/server_tests/test_actions.py b/tests/server_tests/test_actions.py index 6481c755..5758b3ed 100644 --- a/tests/server_tests/test_actions.py +++ b/tests/server_tests/test_actions.py @@ -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 @@ -12,6 +15,9 @@ class TestAction(Action): 'string_field': fields.UnicodeString(), }) + def run(self, request): + pass + class TestActionValidation(object): def setup_method(self, method): @@ -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.') @@ -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