def setUpMultipleResponse(self, responses): request = WebObRequest.blank('http://www.example.com/test') response = MultipleResponse(request, responses) # Clear out _response since that's what we'll be validating response._response = WebObResponse() return response
def setUpMultipleResponse(self, responses): request = WebObRequest.blank('http://www.example.com/test') response = MultipleResponse(request, responses) # Clear out _response since that's what we'll be validating response._response = WebObResponse() return response
def test_body(self): json_boolean = True json_null = None json_number = -1.1 json_object = {"some": "json"} json_string = "json" json_array = [ json_boolean, json_null, json_number, json_object, json_string ] response1 = self.setUpResponse(None, json.dumps(json_boolean)) response2 = self.setUpResponse(None, json.dumps(json_null)) response3 = self.setUpResponse(None, json.dumps(json_number)) response4 = self.setUpResponse(None, json.dumps(json_object)) response5 = self.setUpResponse(None, json.dumps(json_string)) response_array = self.setUpResponse(None, json.dumps(json_array)) responses = [ response1, response2, response3, response4, response5, response_array ] multiple_response = MultipleResponse(self.multiple_response._request, responses) # Clear out _response since that's what we'll be validating multiple_response._response = WebObResponse() multiple_response._merge_responses() json_response = json.loads(multiple_response.response.body) json_booleans = [x for x in json_response if x == json_boolean] self.assertEqual(2, len(json_booleans)) json_nulls = [x for x in json_response if x == json_null] self.assertEqual(2, len(json_nulls)) json_numbers = [x for x in json_response if x == json_number] self.assertEqual(2, len(json_numbers)) json_objects = [x for x in json_response if x == json_object] self.assertEqual(2, len(json_objects)) json_strings = [x for x in json_response if x == json_string] self.assertEqual(2, len(json_strings))
def test_body(self): json_boolean = True json_null = None json_number = -1.1 json_object = {"some": "json"} json_string = "json" json_array = [json_boolean, json_null, json_number, json_object, json_string] response1 = self.setUpResponse(None, json.dumps(json_boolean)) response2 = self.setUpResponse(None, json.dumps(json_null)) response3 = self.setUpResponse(None, json.dumps(json_number)) response4 = self.setUpResponse(None, json.dumps(json_object)) response5 = self.setUpResponse(None, json.dumps(json_string)) response_array = self.setUpResponse(None, json.dumps(json_array)) responses = [response1, response2, response3, response4, response5, response_array] multiple_response = MultipleResponse(self.multiple_response._request, responses) # Clear out _response since that's what we'll be validating multiple_response._response = WebObResponse() multiple_response._merge_responses() json_response = json.loads(multiple_response.response.body) json_booleans = filter(lambda x: x == json_boolean, json_response) self.assertEquals(2, len(json_booleans)) json_nulls = filter(lambda x: x == json_null, json_response) self.assertEquals(2, len(json_nulls)) json_numbers = filter(lambda x: x == json_number, json_response) self.assertEquals(2, len(json_numbers)) json_objects = filter(lambda x: x == json_object, json_response) self.assertEquals(2, len(json_objects)) json_strings = filter(lambda x: x == json_string, json_response) self.assertEquals(2, len(json_strings))