Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_handle_response_request_with_empty_string_response(self):
response = ''
with self.assertRaises(exceptions.ReceivedNoResponse):
self.server._handle_response(response, expected_response=True)
def test_ReceivedNoResponse(self):
with self.assertRaises(exceptions.ReceivedNoResponse):
raise exceptions.ReceivedNoResponse
def test_ReceivedNoResponse(self):
with self.assertRaises(exceptions.ReceivedNoResponse):
raise exceptions.ReceivedNoResponse
def handle_response(response_str, expected_response=True):
"""Processes the response from a request"""
# A response was expected, but none was given?
if expected_response and not len(response_str):
raise exceptions.ReceivedNoResponse()
# Was response given?
if len(response_str):
# Attempt to parse the response
try:
response_dict = json.loads(response_str)
except ValueError:
raise exceptions.ParseError()
# A response was *not* expected, but one was given? It may not
# be necessary to raise here. If we receive a response anyway,
# can't we just ignore it?
if not expected_response and 'result' in response_dict:
raise exceptions.InvalidResponse()