def _test_type(cls, inst): from spyne.util import appreg appreg._applications.clear() class SomeService(ServiceBase): @rpc(_returns=cls, _body_style='bare') def some_call(ctx): return inst prot = HtmlForm(cloth=T_TEST) app = Application([SomeService], 'some_ns', out_protocol=prot) null = NullServer(app, ostr=True) ret = ''.join(null.service.some_call()) try: elt = html.fromstring(ret) except: print(ret) raise show(elt, stdout=False) elt = elt.xpath('//*[@spyne]')[0][ 0] # get the form tag inside the body tag elt = strip_ns(elt) # get rid of namespaces to simplify xpaths in tests print(etree.tostring(elt, pretty_print=True)) return elt
def test_wsdl_validation(self, tmpdir_factory): val = 10 class IntegerService(ServiceBase): @srpc(Integer(ge=20), _returns=Integer) def send(_val): return _val app = Application([IntegerService], 'some_tns', in_protocol=Soap11(validator='lxml'), out_protocol=Soap11(validator='lxml')) # We have to write the WSDL file using a `WsgiApplication` so # that we get a proper transport URL as it would be # `noconn://null.spyne` with NullServer. wsgi_app = WsgiApplication(app) wsgi_app.doc.wsdl11.build_interface_document('mock://foo') wsdl_file = tmpdir_factory.getbasetemp().join('wsdl') wsdl_file.write(wsgi_app.doc.wsdl11.get_interface_document()) server = NullServer(app, ostr=True) c = Client(str(wsdl_file)) with requests_mock.mock() as m: m.post('mock://foo', content=server.service.send(val)[0]) # This should throw because of `Integer(ge=20)` but doesn't. assert c.service.send(10) == val
def test_receiveItemBarCode(): obj = mod.TXml( Header=mod.Header( Message_Type='mt', Company_ID='ci', Version='v', Source='s', Destination='d', Action_Type='read', Sequence_Number=1, Batch_ID='bi', Reference_ID='ri', Msg_Locale='ml', Msg_Time_Zone='mtz', Internal_Date_Time_Stamp='idts', ), Message=mod.Message(ItemBarCodeList=[ mod.ItemBarCode(IsPrimary='ip', ItemCode='ic', Barcode='b', Quantity='q', ActionType='at', BarcodeType='bt', Extensions=[ mod.Extensions( FieldCode='fc', FieldCodeDesc='fcd', FieldValue='fv', ), mod.Extensions( FieldCode='fc', FieldCodeDesc='fcd', FieldValue='fv', ), ]), mod.ItemBarCode(IsPrimary='ip', ItemCode='ic', Barcode='b', Quantity='q', ActionType='at', BarcodeType='bt', Extensions=[ mod.Extensions( FieldCode='fc', FieldCodeDesc='fcd', FieldValue='fv', ), mod.Extensions( FieldCode='fc', FieldCodeDesc='fcd', FieldValue='fv', ), ]), ]), ) server = NullServer( Application([rpc.receiveItemBarCodeService], 'some_tns')) # Using ``_body_style='bare'`` seems to cause to always return # ``None``. Hence we can't check the response object. server.service.receiveItemBarCode(obj)
def test_extensions(self): e = Extensions(FieldCode='fc', FieldCodeDesc='fcd', FieldValue='fv') class ExtensionsService(ServiceBase): @srpc(Extensions, _returns=Extensions) def send(_e): return _e server = NullServer(Application([ExtensionsService], 'some_tns')) assert server.service.send(e) == e
def _test_type(cls, inst): class SomeService(ServiceBase): @rpc(_returns=cls, _body_style='bare') def some_call(ctx): return inst app = Application([SomeService], 'some_ns', out_protocol=HtmlFormTable()) null = NullServer(app, ostr=True) elt = etree.fromstring(''.join(null.service.some_call())) print(etree.tostring(elt, pretty_print=True)) return elt
def _test_type_no_root_cloth(cls, inst): from spyne.util import appreg appreg._applications.clear() class SomeService(ServiceBase): @rpc(_returns=cls, _body_style='bare') def some_call(ctx): return inst prot = HtmlForm() app = Application([SomeService], 'some_ns', out_protocol=prot) null = NullServer(app, ostr=True) elt = etree.fromstring(''.join(null.service.some_call())) show(elt) return elt
def test_item_bar_code(self): e_list = [ Extensions( FieldCode='fc{}'.format(i), FieldCodeDesc='fcd{}'.format(i), FieldValue='fv{}'.format(i)) for i in range(4)] ibc = ItemBarCode(IsPrimary='ip', ItemCode='ic', Barcode='b', Quantity='q', ActionType='at', BarcodeType='bt', Extensions=e_list) class ItemBarCodeService(ServiceBase): @srpc(ItemBarCode, _returns=ItemBarCode) def send(_ibc): return _ibc server = NullServer(Application([ItemBarCodeService], 'some_tns')) assert server.service.send(ibc) == ibc
def test_receiveItemMaster(): obj = mod.TXml( Header=mod.Header( Message_Type='mt', Company_ID='ci', Version='v', Source='s', Destination='d', Action_Type='read', Sequence_Number=1, Batch_ID='bi', Reference_ID='ri', Msg_Locale='ml', Msg_Time_Zone='mtz', Internal_Date_Time_Stamp='idts', ), Message=mod.Message(Item=[ mod.Item(ItemCode='ic', IsStyle='is', ActionType='at', ActivationDate='ad', TargetExclusive='te', OnlineExclusive='oe', EssentialItem='ei', LongDescription='ld', ShortDescription='sd', PrimaryBarcode='pb', HazmatCode='hc', BulkyItem='bi', ItemWeight='iw', ItemHeight='ih', ItemLength='il', ItemWidth='iw', ItemVolume='iv', WeightUOM='wu', DimensionUOM='du', VolumeUOM='vu', IsPerishable='ip', ItemPackageList=[ mod.ItemPackage( PackageType='pt', Description='d', Quantity='q', UnitWeight='uw', UnitWidth='uw', UnitLength='ul', UnitHeight='uh', UnitVolume='uv', WeigthUOM='wu', DimensionUOM='du', VolumeUOM='vu', IsPrimary='ip', BusinessPartnerNumber='bpn', Ti='ti', Hi='hi', ), ], ProductHeirarchy=mod.ProductHeirarchy( Variant='v', Product='p', MerchandiseStyle='ms', Range='r', MajorClass='mc', ClassGroup='cg', Department='d', BusinessGroup='bg', Section='s', Company='c', ), ItemBarCodeList=[ mod.ItemBarCode( IsPrimary='ip', Barcode='b', Quantity='q', ActionType='at', BarcodeType='bt', ), mod.ItemBarCode( IsPrimary='ip', Barcode='b', Quantity='q', ActionType='at', BarcodeType='bt', ), ], PerishableAttribute=mod.PerishableAttribute( ShelfDays='sd', ExpireDateReqd='edr', MinReceivedToExpireDays='mrted', MaxReceivedToExpireDays='mrted', ), WarehouseAttributes=mod.WarehouseAttributes( SecureProduct='sp', Conveyable='c', PutawayType='pt', CrushCode='cc', VolatilityCode='vc', ), Slotting=[ mod.Slotting( LocationCode='lc', SlottingRequired='sr', ), mod.Slotting( LocationCode='lc', SlottingRequired='sr', ), ], ItemPromotion=mod.ItemPromotion( OnPromo='op', PromoStartWeek='psw', ), ItemAttributes=[ mod.ItemAttributes( AttributeTypeId='ati', AttributeTypeDesc='atd', AttributeHeaderId='ahi', AttributeHeaderDesc='ahd', AttributeCodeId='aci', AttributeCode='ac', AttributeCodeDesc='acd', ), mod.ItemAttributes( AttributeTypeId='ati', AttributeTypeDesc='atd', AttributeHeaderId='ahi', AttributeHeaderDesc='ahd', AttributeCodeId='aci', AttributeCode='ac', AttributeCodeDesc='acd', ), ], Extensions=[ mod.Extensions( FieldCode='fc', FieldCodeDesc='fcd', FieldValue='fv', ), mod.Extensions( FieldCode='fc', FieldCodeDesc='fcd', FieldValue='fv', ), ]), ]), ) server = NullServer(Application([rpc.receiveItemMasterService], 'some_tns')) # Using ``_body_style='bare'`` seems to cause to always return # ``None``. Hence we can't check the response object. server.service.receiveItemMaster(obj)