def default_error_response(self, alice_request): """ Default error response will be called on timeout if processing of the request will take more than 2.7s (RESPONSE_TIMEOUT) :param result: dict or AliceRequest :return: AliceResponse """ default_response = self.request.app[ERROR_RESPONSE_KEY] response = alice_request.response(default_response) return generate_json_payload(**response.to_json())
def get_response(self, result, request): """ Make response object from result. :param result: dict or AliceResponse :return: """ if isinstance(result, AliceResponse): return generate_json_payload(**result.to_json()) if result is None: log.critical( 'Got `None` instead of a response!\nGenerating' ' default error response based on %r', request) return self.default_error_response(request) if not isinstance(result, dict): # If result is not a dict, it may cause an error. Warn developer log.warning('Result expected `AliceResponse` or dict, got %r (%r)', type(result), result) return result
def _assert_payload(self, alice_obj, expected_json): json_payload = generate_json_payload(**alice_obj.to_json()) self.assertEqual(json_payload, expected_json)