def test_local_attribute1(self): """ """ self.types_module xml = """<?xml version="1.0" encoding="UTF-8"?> <holder xmlns='urn:subGroup:types'> <baseElt><base>from base</base></baseElt> <childElt><base>from base</base><child>from child</child></childElt></holder>""" ps = ParsedSoap(xml, envelope=False) p1 = ps.Parse(GED("urn:subGroup:types", "holder")) b1 = p1.BaseElt[0] c1 = p1.BaseElt[1] sw = SoapWriter(envelope=False) sw.serialize(p1) ps = ParsedSoap(str(sw), envelope=False) p2 = ps.Parse(GED("urn:subGroup:types", "holder")) b2 = p2.BaseElt[0] c2 = p2.BaseElt[1] self.assertEqual(b1.Base, b2.Base) self.assertEqual(c1.Base, c2.Base) self.assertEqual(c1.Child, c2.Child)
def check_list_defs(self): gl = globals() for klass in map( lambda h: gl[h], filter( lambda g: (g.startswith('TestList') and issubclass( gl[g], ZSI.TC.List)), gl)): typecode = klass('whatever', nillable=True) data = None for i in range(10): sw = SoapWriter() sw.serialize(data, typecode) s = str(sw) print s ps = ParsedSoap(s) pyobj = ps.Parse(typecode) assert pyobj == data, 'Data corruption expected "%s", got "%s"' % ( str(data), str(pyobj)) if data is None: data = [] continue # # cut last 3 fields off: weekday (0-6, Monday is 0), Julian day (day in the year, 1-366), # DST (Daylight Savings Time) flag (-1, 0 or 1) # utc = list(time.gmtime(i)[:-3]) + [999, 0, 0] data.append(tuple(utc))
def test_local_type_substitution1(self): """test extension. Parse known instance, serialize an equivalent, Parse it back. """ attr1 = 'myclass' attr2 = 'whatever' self.types_module pyobj = GED('urn:test', 'test').pyclass() # [ 1489129 ] Unexpected subsitution error message # try to parse before type ever initialized ps = ParsedSoap(MSG1) pyobj0 = ps.Parse(pyobj.typecode) sub0 = pyobj0.Actor self.failUnless(sub0.get_attribute_attr1() == attr1, 'bad attribute1') self.failUnless(sub0.get_attribute_attr2() == attr2, 'bad attribute2') # [ 1489090 ] Derived type attributes don't populate the attr dictionary # pyobj.Actor = sub1 = GTD('urn:test', 'MiddleActor')(None).pyclass() sub1.Element1 = 'foo' sub1.Element2 = 'bar' sub1.set_attribute_attr1(attr1) sub1.set_attribute_attr2(attr2) sw = SoapWriter() sw.serialize(pyobj) xml = str(sw) ps = ParsedSoap(xml) pyobj2 = ps.Parse(pyobj.typecode) sub2 = pyobj2.Actor self.failUnless(sub2.get_attribute_attr1() == attr1, 'bad attribute class') self.failUnless(sub2.get_attribute_attr2() == attr2, 'bad attribute name') # check parsed out correct type self.failUnless( isinstance(sub2.typecode, sub1.typecode.__class__), 'local element actor "%s" must be an instance of "%s"' % (sub2.typecode, sub1.typecode.__class__)) # check local element is derived from base base = GTD('urn:test', 'BaseActor') self.failUnless( isinstance(sub2.typecode, base), 'local element actor must be a derived type of "%s"' % base)
def test_local_type_substitution2(self): """test extension of extension""" attr1 = 'aone' attr2 = 'atwo' attr3 = 'athree' self.types_module pyobj = GED('urn:test', 'test').pyclass() # [ 1489129 ] Unexpected subsitution error message # try to parse before type ever initialized """ ps = ParsedSoap(MSG1) pyobj0 = ps.Parse(pyobj.typecode) sub0 = pyobj0.Actor self.failUnless(sub0.get_attribute_attr1() == attr1, 'bad attribute1') self.failUnless(sub0.get_attribute_attr2() == attr2, 'bad attribute2') """ # [ 1489090 ] Derived type attributes don't populate the attr dictionary # [ 1489677 ] Derivation from derived type missing derived element # pyobj.Actor = sub1 = GTD('urn:test', 'TopActor')(None).pyclass() sub1.Element1 = 'one' sub1.Element2 = 'two' sub1.Element3 = 'three' sub1.set_attribute_attr1(attr1) sub1.set_attribute_attr2(attr2) sub1.set_attribute_attr3(attr3) sw = SoapWriter() sw.serialize(pyobj) xml = str(sw) ps = ParsedSoap(xml) pyobj2 = ps.Parse(pyobj.typecode) sub2 = pyobj2.Actor self.failUnless(sub2.get_attribute_attr1() == attr1, 'bad attribute 1') self.failUnless(sub2.get_attribute_attr2() == attr2, 'bad attribute 2') self.failUnless(sub2.get_attribute_attr3() == attr3, 'bad attribute 3') self.failUnless(sub2.Element1 == sub1.Element1, 'bad element 1') self.failUnless(sub2.Element2 == sub1.Element2, 'bad element 2') self.failUnless(sub2.Element3 == sub1.Element3, 'bad element 3') # check parsed out correct type self.failUnless( isinstance(sub2.typecode, sub1.typecode.__class__), 'local element actor "%s" must be an instance of "%s"' % (sub2.typecode, sub1.typecode.__class__)) # check local element is derived from base base = GTD('urn:test', 'BaseActor') self.failUnless( isinstance(sub2.typecode, base), 'local element actor must be a derived type of "%s"' % base)
def check_union_long(self): import time typecode = GED("http://www.pasoa.org/schemas/version024/PStruct.xsd", "localPAssertionId") for value in (1234455, "whatever", "urn:whatever"): sw = ZSI.SoapWriter() sw.serialize(value, typecode) xml = str(sw) ps = ParsedSoap(xml) pyobj = ps.Parse(typecode) # Union Limitation: # currently it tries to parse it sequentially via memberTypes, # so string is going to parse the URI when we want anyURI self.failUnless(value == pyobj, 'Expected equivalent')
def test_local_empty_attribute(self): # [ 1452752 ] attribute with empty value doesn't appear in parsed object myString = "" pyobj = GED("urn:example", "Test1").pyclass() pyobj.set_attribute_myString(myString) sw = SoapWriter() sw.serialize(pyobj) soap = str(sw) print soap ps = ParsedSoap(soap) pyobj2 = ps.Parse(pyobj.typecode) test = pyobj2.get_attribute_myString() self.failUnlessEqual(myString, str(test))
def test_local_type_substitution_test2(self): """test extension of extension""" attr1 = 'aone' attr2 = 'atwo' attr3 = 'athree' self.types_module pyobj = GED('urn:test', 'test2').pyclass() # Test maxOccurs>1 for substitution # pyobj.Actor = [GTD('urn:test', 'TopActor')(None).pyclass()] sub1 = pyobj.Actor[0] sub1.Element1 = 'one' sub1.Element2 = 'two' sub1.Element3 = 'three' sub1.set_attribute_attr1(attr1) sub1.set_attribute_attr2(attr2) sub1.set_attribute_attr3(attr3) sw = SoapWriter() sw.serialize(pyobj) xml = str(sw) ps = ParsedSoap(xml) pyobj2 = ps.Parse(pyobj.typecode) sub2 = pyobj2.Actor[0] self.failUnless(sub2.get_attribute_attr1() == attr1, 'bad attribute 1') self.failUnless(sub2.get_attribute_attr2() == attr2, 'bad attribute 2') self.failUnless(sub2.get_attribute_attr3() == attr3, 'bad attribute 3') self.failUnless(sub2.Element1 == sub1.Element1, 'bad element 1') self.failUnless(sub2.Element2 == sub1.Element2, 'bad element 2') self.failUnless(sub2.Element3 == sub1.Element3, 'bad element 3') # check parsed out correct type self.failUnless( isinstance(sub2.typecode, sub1.typecode.__class__), 'local element actor "%s" must be an instance of "%s"' % (sub2.typecode, sub1.typecode.__class__)) # check local element is derived from base base = GTD('urn:test', 'BaseActor') self.failUnless( isinstance(sub2.typecode, base), 'local element actor must be a derived type of "%s"' % base)
def test_local_attribute1(self): """ """ myDouble = 4.5 myInt = 9 myFloat = 3.0001 myDecimal = 8.999 myGDateTime = time.gmtime() myAnyURI = "urn:whatever" myQName = ("urn:test", "qbert") myString = "whatever" myHexBinary = hex(888) pyobj = GED("urn:example", "Test1").pyclass() # Test serialize/parse pyobj.set_attribute_myDecimal(myDecimal) pyobj.set_attribute_myDouble(myDouble) pyobj.set_attribute_myFloat(myFloat) pyobj.set_attribute_myInt(myInt) pyobj.set_attribute_myDateTime(myGDateTime) pyobj.set_attribute_myGDay(myGDateTime) pyobj.set_attribute_myGMonth(myGDateTime) pyobj.set_attribute_myGYear(myGDateTime) pyobj.set_attribute_myGYearMonth(myGDateTime) pyobj.set_attribute_myDate(myGDateTime) pyobj.set_attribute_myTime(myGDateTime) pyobj.set_attribute_myAnyURI(myAnyURI) pyobj.set_attribute_myString(myString) pyobj.set_attribute_myHexBinary(myHexBinary) pyobj.set_attribute_myDuration(myGDateTime) # Problems parsings pyobj.set_attribute_myQName(myQName) pyobj.set_attribute_myGMonthDay(myGDateTime) #TODO: #pyobj.set_attribute_myBase64Binary("") #pyobj.set_attribute_myNOTATION("NOT") sw = SoapWriter() sw.serialize(pyobj) soap = str(sw) ps = ParsedSoap(soap) pyobj2 = ps.Parse(pyobj.typecode) test = pyobj2.get_attribute_myInt() self.failUnlessEqual(myInt, test) test = pyobj2.get_attribute_myDouble() self.failUnlessEqual(myDouble, test) test = pyobj2.get_attribute_myFloat() self.failUnlessEqual(myFloat, test) test = pyobj2.get_attribute_myDecimal() self.failUnlessEqual(myDecimal, test) test = pyobj2.get_attribute_myAnyURI() self.failUnlessEqual(myAnyURI, test) test = pyobj2.get_attribute_myQName() self.failUnlessEqual(myQName, test) test = pyobj2.get_attribute_myString() self.failUnlessEqual(myString, test) test = pyobj2.get_attribute_myHexBinary() self.failUnlessEqual(myHexBinary, test) # DateTime stuff test = pyobj2.get_attribute_myDateTime() self.failUnlessEqual(myGDateTime[:-3], test[:-3]) test = pyobj2.get_attribute_myDate() self.failUnlessEqual(myGDateTime[:3], test[:3]) test = pyobj2.get_attribute_myTime() self.failUnlessEqual(myGDateTime[4:5], test[4:5]) test = pyobj.get_attribute_myDuration() self.failUnlessEqual(myGDateTime, test) # Bug [ 1453421 ] Incorrect format for type gDay test = pyobj2.get_attribute_myGDay() self.failUnlessEqual(myGDateTime[2], test[2]) test = pyobj2.get_attribute_myGMonth() self.failUnlessEqual(myGDateTime[1], test[1]) test = pyobj2.get_attribute_myGYear() self.failUnlessEqual(myGDateTime[0], test[0]) test = pyobj2.get_attribute_myGYearMonth() self.failUnlessEqual(myGDateTime[:2], test[:2])