示例#1
0
class TestXmlSerializer(TestCase):
    
    def setUp(self):
        self.serializer = XmlSerializer()
    
    def test_serialize(self):
        response = self.serializer.serialize({"test": "this"})
        self.assertEqual(response["Content-Type"], "application/xml; charset=utf-8")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, '<?xml version="1.0" encoding="utf-8"?><response><test>this</test></response>')
        self.assertEqual(response.data_dict, {"test": "this"})
        
        response = self.serializer.serialize([{"one": "more"}, {"set": "now"}])
        self.assertEqual(response.content, '<?xml version="1.0" encoding="utf-8"?><response><objects type="list"><object><one>more</one></object><object><set>now</set></object></objects></response>')
        self.assertEqual(response.data_dict, [{"one": "more"}, {"set": "now"}])
示例#2
0
 def setUp(self):
     self.serializer = XmlSerializer()