def setUp(self): from libcloudcore.drivers.aws.route53 import Driver self.model = Driver.model self.layer = XmlSerializer()
class TestXmlSerializer(unittest.TestCase): def setUp(self): from libcloudcore.drivers.aws.route53 import Driver self.model = Driver.model self.layer = XmlSerializer() def test_parse(self): xml = """ <?xml version="1.0" encoding="UTF-8"?> <ListHostedZonesByNameResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"> <HostedZones> <HostedZone> <Id>/hostedzone/ZONE_ID</Id> <Name>www.example.com</Name> <CallerReference>CALLER_REFERENCE</CallerReference> <Config> <Comment>COMMENT</Comment> <PrivateZone>true</PrivateZone> </Config> <ResourceRecordSetCount>0</ResourceRecordSetCount> </HostedZone> </HostedZones> <IsTruncated>false</IsTruncated> <MaxItems>10</MaxItems> </ListHostedZonesByNameResponse>""".strip() operation = self.model.get_operation("ListHostedZonesByName") shape = operation.output_shape self.assertEqual(self.layer.deserialize(operation, shape, xml), { "HostedZones": [{ "Id": "/hostedzone/ZONE_ID", "Name": "www.example.com", "CallerReference": "CALLER_REFERENCE", "Config": { "Comment": "COMMENT", "PrivateZone": True, }, "ResourceRecordSetCount": 0, }], "IsTruncated": False, "MaxItems": "10", }) def test_serialize(self): operation = self.model.get_operation("ListHostedZonesByName") result = self.layer.serialize( operation, operation.output_shape, dict( HostedZones=[{ "Id": "/hostedzone/ZONE_ID", "Name": "www.example.com", "CallerReference": "CALLER_REFERENCE", "Config": { "Comment": "COMMENT", "PrivateZone": True, }, "ResourceRecordSetCount": 0, }], ), ) xml = """ <ListHostedZonesByNameResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"> <HostedZones> <HostedZone> <Id>/hostedzone/ZONE_ID</Id> <Name>www.example.com</Name> <CallerReference>CALLER_REFERENCE</CallerReference> <Config> <Comment>COMMENT</Comment> <PrivateZone>true</PrivateZone> </Config> <ResourceRecordSetCount>0</ResourceRecordSetCount> </HostedZone> </HostedZones> </ListHostedZonesByNameResponse>""".strip() self.assertEqual(xmltodict.parse(result), xmltodict.parse(xml))