示例#1
0
 def test_view_call_final(self):
     response = self.client.options('/mock/final/')
     self.assertEqual(response['Content-Type'].split(';')[0],
                      "application/json")
     parser = JSONParser(None)
     (data, files) = parser.parse(StringIO(response.content))
     self.assertEqual(data['test'], 'passed')
    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)    
示例#3
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)
示例#4
0
 def _verify_options_response(self, response, name, description, fields=None, status=200,
                              mime_type='application/json'):
     self.assertEqual(response.status_code, status)
     self.assertEqual(response['Content-Type'].split(';')[0], mime_type)
     parser = JSONParser(None)
     (data, files) = parser.parse(StringIO(response.content))
     self.assertTrue('application/json' in data['renders'])
     self.assertEqual(name, data['name'])
     self.assertEqual(description, data['description'])
     if fields is None:
         self.assertFalse(hasattr(data, 'fields'))
     else:
         self.assertEqual(data['fields'], fields)
示例#5
0
 def _verify_options_response(
     self, response, name, description, fields=None, status=200, mime_type="application/json"
 ):
     self.assertEqual(response.status_code, status)
     self.assertEqual(response["Content-Type"].split(";")[0], mime_type)
     parser = JSONParser(None)
     (data, files) = parser.parse(StringIO(response.content.decode(settings.DEFAULT_CHARSET)))
     self.assertTrue("application/json" in data["renders"])
     self.assertEqual(name, data["name"])
     self.assertEqual(description, data["description"])
     if fields is None:
         self.assertFalse(hasattr(data, "fields"))
     else:
         self.assertEqual(data["fields"], fields)
示例#6
0
 def _verify_options_response(self,
                              response,
                              name,
                              description,
                              fields=None,
                              status=200,
                              mime_type='application/json'):
     self.assertEqual(response.status_code, status)
     self.assertEqual(response['Content-Type'].split(';')[0], mime_type)
     parser = JSONParser(None)
     (data, files) = parser.parse(StringIO(response.content))
     self.assertTrue('application/json' in data['renders'])
     self.assertEqual(name, data['name'])
     self.assertEqual(description, data['description'])
     if fields is None:
         self.assertFalse(hasattr(data, 'fields'))
     else:
         self.assertEqual(data['fields'], fields)
示例#7
0
 def test_view_call_final(self):
     response = self.client.options('/mock/final/')
     self.assertEqual(response['Content-Type'].split(';')[0], "application/json")
     parser = JSONParser(None)
     (data, files) = parser.parse(StringIO(response.content))
     self.assertEqual(data['test'], 'passed')
示例#8
0
 def test_view_call_final(self):
     response = self.client.options("/mock/final/")
     self.assertEqual(response["Content-Type"].split(";")[0], "application/json")
     parser = JSONParser(None)
     (data, files) = parser.parse(StringIO(response.content.decode(settings.DEFAULT_CHARSET)))
     self.assertEqual(data["test"], "passed")