def test_json_decoding_error(self): deferred = Deferred() twisted_headers = Headers({"Content-Type": ["application/json"]}) twisted_response = TWResponse( ("HTTP", 1, 1), 200, "OK", twisted_headers, None) request = Request( method="GET", url="/", kwargs={ "headers": { "Content-Type": "application/json"}, "data": None}) r = Response(deferred, twisted_response, request) r._done = True with self.assertRaisesRegexp(ValueError, re.compile( "No JSON object could be decoded")): r.json()
def test_json_wrong_content_type(self): deferred = Deferred() twisted_headers = Headers({"Content-Type": ["text/html"]}) twisted_response = TWResponse( ("HTTP", 1, 1), 200, "OK", twisted_headers, None) request = Request( method="GET", url="/", kwargs={ "headers": { "Content-Type": "text/html"}, "data": None}) r = Response(deferred, twisted_response, request) r._done = True with self.assertRaisesRegexp( ValueError, re.compile("Not an application/json response\.")): r.json()