Exemplo n.º 1
0
 def test_with_content_type_args(self):
     """
     Test JSON rendering with additional content type arguments supplied. 
     """
     obj = {'foo':['bar','baz']}
     renderer = JSONRenderer(None)
     content = renderer.render(obj, 'application/json; indent=2')
     self.assertEquals(content, _indented_repr)
 def test_without_content_type_args(self):
     """
     Test basic JSON rendering.
     """
     obj = {'foo': ['bar', 'baz']}
     renderer = JSONRenderer(None)
     content = renderer.render(obj, 'application/json')
     self.assertEquals(content, _flat_repr)
Exemplo n.º 3
0
 def test_without_content_type_args(self):
     """
     Test basic JSON rendering.
     """
     obj = {'foo':['bar','baz']}
     renderer = JSONRenderer(None)
     content = renderer.render(obj, 'application/json')
     self.assertEquals(content, _flat_repr)
Exemplo n.º 4
0
 def test_with_content_type_args(self):
     """
     Test JSON rendering with additional content type arguments supplied.
     """
     obj = {'foo': ['bar', 'baz']}
     renderer = JSONRenderer(None)
     content = renderer.render(obj, 'application/json; indent=2')
     self.assertEquals(strip_trailing_whitespace(content), _indented_repr)
Exemplo n.º 5
0
 def test_with_content_type_args(self):
     """
     Test JSON rendering with additional content type arguments supplied.
     """
     obj = {"foo": ["bar", "baz"]}
     renderer = JSONRenderer(None)
     content = renderer.render(obj, "application/json; indent=2")
     self.assertEquals(strip_trailing_whitespace(content), _indented_repr)
 def test_without_content_type_args(self):
     """
     Test basic JSON rendering.
     """
     obj = {"foo": ["bar", "baz"]}
     renderer = JSONRenderer(None)
     content = renderer.render(obj, "application/json")
     self.assertEquals(content, _flat_repr)
Exemplo n.º 7
0
 def test_without_content_type_args(self):
     """
     Test basic JSON rendering.
     """
     obj = {'foo': ['bar', 'baz']}
     renderer = JSONRenderer(None)
     content = renderer.render(obj, 'application/json')
     # Fix failing test case which depends on version of JSON library.
     self.assertEquals(content, _flat_repr)
Exemplo n.º 8
0
    def test_render_and_parse(self):
        """
        Test rendering and then parsing returns the original object.
        IE obj -> render -> parse -> obj.
        """
        obj = {'foo':['bar','baz']}

        renderer = JSONRenderer(None)
        parser = JSONParser(None)

        content = renderer.render(obj, 'application/json')
        (data, files) = parser.parse(StringIO(content))
        self.assertEquals(obj, data)    
Exemplo n.º 9
0
    def test_render_and_parse(self):
        """
        Test rendering and then parsing returns the original object.
        IE obj -> render -> parse -> obj.
        """
        obj = {'foo': ['bar', 'baz']}

        renderer = JSONRenderer(None)
        parser = JSONParser(None)

        content = renderer.render(obj, 'application/json')
        (data, files) = parser.parse(StringIO(content))
        self.assertEquals(obj, data)
Exemplo n.º 10
0
def get_colors_json():
    """
    This is a surprising kludge to get the json from a
    DRF resource, outside of a true request/response context

    for a simple resource - most easily mocked by doing list(queryset.values(fields))
    """
    resource_view = ListOrCreateModelView(resource=ColorResource)
    dummy_request = HttpRequest()
    response_obj = resource_view.get(dummy_request)
    response = Response(status.HTTP_200_OK, response_obj)
    jsonr = JSONRenderer(resource_view)
    filtered_content = resource_view.filter_response(response_obj)
    # json_string = jsonr.render(filtered_content)
    return filtered_content
Exemplo n.º 11
0
 def test_with_content_type_args(self):
     obj = {'foo':['bar','baz']}
     renderer = JSONRenderer(None)
     content = renderer.render(obj, 'application/json; indent=2')
     self.assertEquals(content, _indented_repr)