Пример #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')
Пример #2
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)    
Пример #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")