def test_local_choice_default_facets_legal1(self): """<choice minOccurs=1 maxOccurs=1> """ pyobj = GED("urn:example", "Easy").pyclass() pyobj.Rank = 1 sw = SoapWriter() sw.serialize(pyobj) print(str(sw))
def test_local_choice_default_facets_legal1(self): """<choice minOccurs=1 maxOccurs=1> """ pyobj = GED("urn:example", "Easy").pyclass() pyobj.Rank = 1 sw = SoapWriter() sw.serialize(pyobj) print str(sw)
def test_local_choice_maxOccurs_unbounded(self): """<choice minOccurs=1 maxOccurs=unbounded> """ pyobj = GED("urn:example", "Hard").pyclass() pyobj.Name = ["steve", "mark"] pyobj.Any = ["whatever"] pyobj.Rank = [2, 3, 4] sw = SoapWriter() sw.serialize(pyobj) print(str(sw))
def test_local_choice_maxOccurs_unbounded(self): """<choice minOccurs=1 maxOccurs=unbounded> """ pyobj = GED("urn:example", "Hard").pyclass() pyobj.Name = ["steve", "mark"] pyobj.Any = ["whatever"] pyobj.Rank = [2,3,4] sw = SoapWriter() sw.serialize(pyobj) print str(sw)
def test_local_choice_maxOccurs_unbounded(self): """<choice minOccurs=1 maxOccurs=unbounded> """ pyobj = GED("urn:example", "Hard").pyclass() pyobj.Name = "steve" pyobj.Name.append("mark") pyobj.Any = "whatever" pyobj.Rank = 2 pyobj.Rank.append(3) pyobj.Rank.append(4) sw = SoapWriter() sw.serialize(pyobj) print(str(sw))
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_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_serialize1(): """ <element name="GlobalElementLocalType"> <complexType> <sequence> <element name="Unqualified1"> <complexType/> </element> <element name="Unqualified2" type="xsd:int"/> <element name="Unqualified3" type="tns:GlobalType"/> <element name="Unqualified4"> <simpleType> <restriction base="xsd:string"/> </simpleType> </element> </sequence> </complexType> </element> """ tns = "urn:test" pyobj = GED(tns, "GlobalElementLocalType").pyclass() pyobj.Unqualified1 = pyobj.new_Unqualified1() pyobj.Unqualified2 = 2 pyobj.Unqualified3 = pyobj.new_Unqualified3() pyobj.Unqualified3.Unqualified1 = pyobj.Unqualified3.new_Unqualified1() pyobj.Unqualified3.Unqualified2 = 32 pyobj.Unqualified4 = "whatever" sw = SoapWriter(envelope=False) sw.serialize(pyobj) xml = str(sw) print xml et = ElementTree.fromstring(xml) # GlobalElementLocalType assert (et.tag == '{urn:test}GlobalElementLocalType'), "root GED" for i, j in zip( ['Unqualified1', 'Unqualified2', 'Unqualified3', 'Unqualified4'], map(lambda c: c.tag, et.getchildren())): assert (i == j), 'Match Failed: expected "%s" not "%s"' % (i, j)
def _test_local_serialize1(): """ <element name="GlobalElementLocalType"> <complexType> <sequence> <element name="Unqualified1"> <complexType/> </element> <element name="Unqualified2" type="xsd:int"/> <element name="Unqualified3" type="tns:GlobalType"/> <element name="Unqualified4"> <simpleType> <restriction base="xsd:string"/> </simpleType> </element> </sequence> </complexType> </element> """ tns = "urn:test" pyobj = GED(tns, "GlobalElementLocalType").pyclass() pyobj.Unqualified1 = pyobj.new_Unqualified1() pyobj.Unqualified2 = 2 pyobj.Unqualified3 = pyobj.new_Unqualified3() pyobj.Unqualified3.Unqualified1 = pyobj.Unqualified3.new_Unqualified1() pyobj.Unqualified3.Unqualified2 = 32 pyobj.Unqualified4 = "whatever" sw = SoapWriter(envelope=False) sw.serialize(pyobj) xml = str(sw) print xml et = ElementTree.fromstring(xml) # GlobalElementLocalType assert(et.tag == '{urn:test}GlobalElementLocalType'), "root GED" for i,j in zip([ 'Unqualified1', 'Unqualified2', 'Unqualified3', 'Unqualified4'], map(lambda c: c.tag, et.getchildren())): assert(i == j), 'Match Failed: expected "%s" not "%s"' %(i,j)
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])