Merge pull request #528 from tianhao64/master

Fixes #519, #448, #420, #421 Fix SoapAdapter serializer to support se…
This commit is contained in:
Tianhao He 2017-03-21 11:57:54 -07:00 committed by GitHub
commit 912e365564
2 changed files with 12 additions and 1 deletions

@ -448,7 +448,7 @@ class SoapSerializer:
# a bug.
val = val.decode(XML_ENCODING)
result = XmlEscape(val)
self.writer.write('<{0}{1}>{2}</{0}>'.format(info.name, attr, result))
self.writer.write(u'<{0}{1}>{2}</{0}>'.format(info.name, attr, result))
## Serialize a a data object (internal)
#

@ -1,3 +1,5 @@
# -*- coding: utf-8 -*-
# VMware vSphere Python SDK
# Copyright (c) 2008-2015 VMware, Inc. All Rights Reserved.
#
@ -40,6 +42,14 @@ class SerializerTests(tests.VCRTestBase):
pc.diskSpaceToAddressSpaceRatio = 1.0
SoapAdapter.Serialize(pc, version='vim.version.version10')
def test_serialize_unicode(self):
self.assertEqual(SoapAdapter.SerializeToUnicode(''),
u'<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:vim25" xsi:type="xsd:string">\u1e02</object>')
self.assertEqual(SoapAdapter.SerializeToUnicode(u''),
u'<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:vim25" xsi:type="xsd:string">\u1e02</object>')
self.assertEqual(SoapAdapter.SerializeToUnicode(u'\u1e02'),
u'<object xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:vim25" xsi:type="xsd:string">\u1e02</object>')
def _base_serialize_test(self, soap_creator, request_matcher):
my_vcr = config.VCR(
custom_patches=(
@ -99,3 +109,4 @@ class SerializerTests(tests.VCRTestBase):
self._base_serialize_test(soap_creator, request_matcher)
finally:
GetRequestContext().pop("vcSessionCookie")