mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
Merge 02be2b68b3
into 3fcc076d91
This commit is contained in:
commit
c373303ed1
|
@ -88,8 +88,12 @@ class JSONRenderer(BaseRenderer):
|
|||
"""
|
||||
Render `data` into JSON, returning a bytestring.
|
||||
"""
|
||||
if data is None:
|
||||
return bytes()
|
||||
response = None
|
||||
if renderer_context:
|
||||
response = renderer_context.get('response', None)
|
||||
|
||||
if response is not None and response.status_code == 204:
|
||||
return b''
|
||||
|
||||
renderer_context = renderer_context or {}
|
||||
indent = self.get_indent(accepted_media_type, renderer_context)
|
||||
|
|
|
@ -313,6 +313,17 @@ class JSONRendererTests(TestCase):
|
|||
data = json.loads(ret.decode('utf-8'))
|
||||
self.assertEqual(data, [[o.id, o.name]])
|
||||
|
||||
def test_render_valid_json_when_data_is_none(self):
|
||||
result = JSONRenderer().render(None)
|
||||
self.assertEqual(result, b'null')
|
||||
|
||||
def test_render_no_content_on_204_response(self):
|
||||
context = {
|
||||
'response': Response(status=204),
|
||||
}
|
||||
result = JSONRenderer().render(None, renderer_context=context)
|
||||
self.assertEqual(result, b'')
|
||||
|
||||
def test_render_dict_abc_obj(self):
|
||||
class Dict(MutableMapping):
|
||||
def __init__(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user