def test_wsgi_for_filled_response(self): response = Response() response.status = 400 response.headers['Content-Type'] = 'application/json' response.body = b'{"error": "Invalid token"}' expected_status = '400 Bad Request' expected_headers = {'Content-Type': 'application/json'} expected_body = b'{"error": "Invalid token"}' self.assert_response(response, expected_status, expected_headers, expected_body)
def test_string_body_gets_converted_to_bytes(self): response = Response() response.body = 'hello world' self.assertEqual(response._wsgi_body(), (b'hello world', ))
def test_can_concatenate_bytes_to_previously_set_body_string(self): response = Response() response.body = 'hello' response.body += b' world' self.assertEqual(response.body, b'hello world')
def test_setting_body_converts_any_object_into_its_string_representation( self): response = Response() response.body = {'foo': 'bar'} self.assertEqual(response.body, b"{'foo': 'bar'}")
def test_string_gets_converted_to_bytes_when_set_to_body(self): response = Response() response.body = 'hello world' self.assertEqual(response.body, b'hello world')