def test_compact(self):
     renderer = JSONRenderer()
     data = OrderedDict([('a', 1), ('b', 2)])
     context = {'indent': 4}
     assert (
         renderer.render(data, renderer_context=context) ==
         b'{\n    "a": 1,\n    "b": 2\n}'
     )
 def test_u2028_u2029(self):
     # The \u2028 and \u2029 characters should be escaped,
     # even when the non-escaping unicode representation is used.
     # Regression test for #2169
     obj = {'should_escape': '\u2028\u2029'}
     renderer = JSONRenderer()
     content = renderer.render(obj, 'application/json')
     self.assertEqual(content, '{"should_escape":"\\u2028\\u2029"}'.encode('utf-8'))
 def test_with_content_type_args(self):
     """
     Test JSON rendering with additional content type arguments supplied.
     """
     obj = {'foo': ['bar', 'baz']}
     renderer = JSONRenderer()
     content = renderer.render(obj, 'application/json; indent=2')
     self.assertEqual(strip_trailing_whitespace(content.decode('utf-8')), _indented_repr)
 def test_without_content_type_args(self):
     """
     Test basic JSON rendering.
     """
     obj = {'foo': ['bar', 'baz']}
     renderer = JSONRenderer()
     content = renderer.render(obj, 'application/json')
     # Fix failing test case which depends on version of JSON library.
     self.assertEqual(content.decode('utf-8'), _flat_repr)
 def test_long_form(self):
     renderer = JSONRenderer()
     renderer.compact = False
     data = OrderedDict([('a', 1), ('b', 2)])
     assert renderer.render(data) == b'{"a": 1, "b": 2}'
 def test_indented(self):
     renderer = JSONRenderer()
     data = OrderedDict([('a', 1), ('b', 2)])
     assert renderer.render(data) == b'{"a":1,"b":2}'
 def test_proper_encoding(self):
     obj = {'countries': ['United Kingdom', 'France', 'España']}
     renderer = JSONRenderer()
     content = renderer.render(obj, 'application/json')
     self.assertEqual(content, '{"countries":["United Kingdom","France","España"]}'.encode('utf-8'))