Exemplo n.º 1
0
    def test_encode_json_data_none(self):
        data = {"param1": "value 1", "param2": None}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": null', body)
        self.assertIn('"param1": "value 1"', body)
Exemplo n.º 2
0
    def test_encode_json_data_including_array(self):
        data = {"param1": "value 1", "param2": ["value2", "value3"]}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": ["value2", "value3"]', body)
        self.assertIn('"param1": "value 1"', body)
Exemplo n.º 3
0
    def test_encode_json_data_unicode(self):
        data = {"param1": u"العَرَبِ", "param2": [u"válue", "value3"]}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": ["v\\u00e1lue", "value3"]', body)
        self.assertIn('"param1": "\\u0627\\u0644\\u0639\\u064e\\u0631\\u064e\\u0628\\u0650"', body)
Exemplo n.º 4
0
    def test_encode_json_data_as_2tuple_parameter(self):
        data = [("param1", "value 1"), ("param2", "value2"), ("param2", "value3")]

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": ["value2", "value3"]', body)
        self.assertIn('"param1": "value 1"', body)
Exemplo n.º 5
0
    def test_encode_json_data_none(self):
        data = {"param1": "value 1", "param2": None}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": null', body)
        self.assertIn(b'"param1": "value 1"', body)
Exemplo n.º 6
0
    def test_encode_json_data_unicode(self):
        data = {"param1": u"العَرَبِ", "param2": [u"válue", "value3"]}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": ["v\\u00e1lue", "value3"]', body)
        self.assertIn(b'"param1": "\\u0627\\u0644\\u0639\\u064e\\u0631\\u064e\\u0628\\u0650"', body)
Exemplo n.º 7
0
    def test_encode_json_data_including_array(self):
        data = {"param1": "value 1", "param2": ["value2", "value3"]}

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": ["value2", "value3"]', body)
        self.assertIn(b'"param1": "value 1"', body)
Exemplo n.º 8
0
    def test_encode_json_data_as_2tuple_parameter(self):
        data = [("param1", "value 1"), ("param2", "value2"), ("param2", "value3")]

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": ["value2", "value3"]', body)
        self.assertIn(b'"param1": "value 1"', body)
Exemplo n.º 9
0
    def test_encode_json_data_files(self):
        files = {"file_upload": "resources/file.pdf", "file_upload2": "resources/file.png"}
        data = {"param1": "value1", "param2": "value2"}

        r = JSONRenderer()
        body, content_type = r.encode_params(data, files=files)
        self.assertEqual(content_type, "application/json")
        self.assertIn('"param2": "value2"', body)
        self.assertIn('"param1": "value1"', body)
        self.assertNotIn("file_upload", body)
Exemplo n.º 10
0
    def test_encode_json_data_files(self):
        files = {"file_upload": "resources/file.pdf", "file_upload2": "resources/file.png"}
        data = {"param1": "value1", "param2": "value2"}

        r = JSONRenderer()
        body, content_type = r.encode_params(data, files=files)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'"param2": "value2"', body)
        self.assertIn(b'"param1": "value1"', body)
        self.assertNotIn(b"file_upload", body)
Exemplo n.º 11
0
    def test_encode_json_data_array_of_dictionaries(self):
        data = [
            {"param1": "value 1", "param2": "value 2", "param3": "value 3"},
            {"param1": "value 1"}
        ]

        r = JSONRenderer()
        body, content_type = r.encode_params(data)
        self.assertEqual(content_type, "application/json")
        self.assertIn(b'[{"', body)
        self.assertIn(b'"param1": "value 1"', body)
        self.assertIn(b'"param2": "value 2"', body)
        self.assertIn(b'"param3": "value 3"', body)
        self.assertIn(b', {"param1": "value 1"}]', body)
Exemplo n.º 12
0
 def test_encode_json_no_data(self):
     r = JSONRenderer()
     body, content_type = r.encode_params()
     self.assertEqual(content_type, "application/json")
     self.assertEqual("", body)
Exemplo n.º 13
0
 def test_encode_json_no_data(self):
     r = JSONRenderer()
     body, content_type = r.encode_params()
     self.assertEqual(content_type, "application/json")
     self.assertEqual(b"", body)