@@ -474,21 +474,25 @@ class XmlModel(Model):
474474 def test_complex_namespace (self ):
475475 """Test recursive namespace."""
476476 basic_xml = """<?xml version="1.0"?>
477- <entry xmlns="http://www.w3.org/2005/Atom">
477+ <entry xmlns="http://www.w3.org/2005/Atom" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" >
478478 <author>
479479 <name>lmazuel</name>
480480 </author>
481481 <AuthorizationRules xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
482- <AuthorizationRule>
482+ <AuthorizationRule i:type="SharedAccessAuthorizationRule" >
483483 <KeyName>testpolicy</KeyName>
484484 </AuthorizationRule>
485485 </AuthorizationRules>
486+ <CountDetails xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
487+ <d2p1:ActiveMessageCount xmlns:d2p1="http://schemas.microsoft.com/netservices/2011/06/servicebus">12</d2p1:ActiveMessageCount>
488+ </CountDetails>
486489 </entry>"""
487490
488491 class XmlRoot (Model ):
489492 _attribute_map = {
490493 'author' : {'key' : 'author' , 'type' : 'QueueDescriptionResponseAuthor' },
491494 'authorization_rules' : {'key' : 'AuthorizationRules' , 'type' : '[AuthorizationRule]' , 'xml' : {'ns' : 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect' , 'wrapped' : True , 'itemsNs' : 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect' }},
495+ 'message_count_details' : {'key' : 'MessageCountDetails' , 'type' : 'MessageCountDetails' },
492496 }
493497 _xml_map = {
494498 'name' : 'entry' , 'ns' : 'http://www.w3.org/2005/Atom'
@@ -504,22 +508,34 @@ class QueueDescriptionResponseAuthor(Model):
504508
505509 class AuthorizationRule (Model ):
506510 _attribute_map = {
511+ 'type' : {'key' : 'type' , 'type' : 'str' , 'xml' : {'attr' : True , 'prefix' : 'i' , 'ns' : 'http://www.w3.org/2001/XMLSchema-instance' }},
507512 'key_name' : {'key' : 'KeyName' , 'type' : 'str' , 'xml' : {'ns' : 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect' }},
508513 }
509514 _xml_map = {
510515 'ns' : 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'
511516 }
512517
518+ class MessageCountDetails (Model ):
519+ _attribute_map = {
520+ 'active_message_count' : {'key' : 'ActiveMessageCount' , 'type' : 'int' , 'xml' : {'prefix' : 'd2p1' , 'ns' : 'http://schemas.microsoft.com/netservices/2011/06/servicebus' }},
521+ }
522+ _xml_map = {
523+ 'name' : 'CountDetails' , 'ns' : 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'
524+ }
525+
513526
514527 s = Deserializer ({
515528 "XmlRoot" : XmlRoot ,
516529 "QueueDescriptionResponseAuthor" : QueueDescriptionResponseAuthor ,
517530 "AuthorizationRule" : AuthorizationRule ,
531+ "MessageCountDetails" : MessageCountDetails ,
518532 })
519533 result = s (XmlRoot , basic_xml , "application/xml" )
520534
521535 assert result .author .name == "lmazuel"
522536 assert result .authorization_rules [0 ].key_name == "testpolicy"
537+ assert result .authorization_rules [0 ].type == "SharedAccessAuthorizationRule"
538+ assert result .message_count_details .active_message_count == 12
523539
524540
525541class TestXmlSerialization :
@@ -1409,4 +1425,63 @@ class XmlModel(Model):
14091425 s = Serializer ({"XmlModel" : XmlModel })
14101426 rawxml = s .body (mymodel , 'XmlModel' , is_xml = True )
14111427
1412- assert_xml_equals (rawxml , basic_xml )
1428+ assert_xml_equals (rawxml , basic_xml )
1429+
1430+ @pytest .mark .skipif (sys .version_info < (3 ,6 ),
1431+ reason = "Unstable before python3.6 for some reasons" )
1432+ def test_complex_namespace (self ):
1433+ """Test recursive namespace."""
1434+ basic_xml = ET .fromstring ("""<?xml version="1.0"?>
1435+ <entry xmlns="http://www.w3.org/2005/Atom" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
1436+ <author>
1437+ <name>lmazuel</name>
1438+ </author>
1439+ <AuthorizationRules xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
1440+ <AuthorizationRule i:type="SharedAccessAuthorizationRule">
1441+ <KeyName>testpolicy</KeyName>
1442+ </AuthorizationRule>
1443+ </AuthorizationRules>
1444+ </entry>""" )
1445+
1446+ class XmlRoot (Model ):
1447+ _attribute_map = {
1448+ 'author' : {'key' : 'author' , 'type' : 'QueueDescriptionResponseAuthor' },
1449+ 'authorization_rules' : {'key' : 'AuthorizationRules' , 'type' : '[AuthorizationRule]' , 'xml' : {'ns' : 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect' , 'wrapped' : True , 'itemsNs' : 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect' }},
1450+ }
1451+ _xml_map = {
1452+ 'name' : 'entry' , 'ns' : 'http://www.w3.org/2005/Atom'
1453+ }
1454+
1455+ class QueueDescriptionResponseAuthor (Model ):
1456+ _attribute_map = {
1457+ 'name' : {'key' : 'name' , 'type' : 'str' , 'xml' : {'ns' : 'http://www.w3.org/2005/Atom' }},
1458+ }
1459+ _xml_map = {
1460+ 'ns' : 'http://www.w3.org/2005/Atom'
1461+ }
1462+
1463+ class AuthorizationRule (Model ):
1464+ _attribute_map = {
1465+ 'type' : {'key' : 'type' , 'type' : 'str' , 'xml' : {'attr' : True , 'prefix' : 'i' , 'ns' : 'http://www.w3.org/2001/XMLSchema-instance' }},
1466+ 'key_name' : {'key' : 'KeyName' , 'type' : 'str' , 'xml' : {'ns' : 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect' }},
1467+ }
1468+ _xml_map = {
1469+ 'ns' : 'http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'
1470+ }
1471+
1472+ mymodel = XmlRoot (
1473+ author = QueueDescriptionResponseAuthor (name = "lmazuel" ),
1474+ authorization_rules = [AuthorizationRule (
1475+ type = "SharedAccessAuthorizationRule" ,
1476+ key_name = "testpolicy"
1477+ )]
1478+ )
1479+
1480+ s = Serializer ({
1481+ "XmlRoot" : XmlRoot ,
1482+ "QueueDescriptionResponseAuthor" : QueueDescriptionResponseAuthor ,
1483+ "AuthorizationRule" : AuthorizationRule ,
1484+ })
1485+ rawxml = s .body (mymodel , 'XmlModel' )
1486+
1487+ assert_xml_equals (rawxml , basic_xml )
0 commit comments