如何为使用ZSI包的python客户机创建Mock?

2024-04-26 12:16:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个客户端代码是用ZSI编写的我想建立一个静态响应模拟。我试图使用urllib2包,但它不工作,因为返回类型是字符串在urllib2和这里的响应是另一种类型,我不知道。帮助我。。。有人能帮我吗?你知道吗

代码:

from PayDayLoans_services_types import *
import urlparse, types
from ZSI.TCcompound import ComplexType, Struct
from ZSI import client
import ZSI

# Locator
class PayDayLoansLocator:
    PayDayLoansSoap_address = "https://something.com/something.asmx"
    def getPayDayLoansSoapAddress(self):
        return PayDayLoansLocator.PayDayLoansSoap_address
    def getPayDayLoansSoap(self, url=None, **kw):
        return PayDayLoansSoapSOAP(url or PayDayLoansLocator.PayDayLoansSoap_address, **kw)

# Methods
class PayDayLoansSoapSOAP:
    def __init__(self, url, **kw):
        kw.setdefault("readerclass", None)
        kw.setdefault("writerclass", None)
        # no resource properties
        self.binding = client.Binding(url=url, **kw)
        # no ws-addressing

    # op: LoanResubmitXML
    def LoanResubmitXML(self, request):
        if isinstance(request, LoanResubmitXMLSoapIn) is False:
            raise TypeError, "%s incorrect request type" % (request.__class__)
        kw = {}
        # no input wsaction
        self.binding.Send(None, None, request, soapaction="http://www.something.com/Request/ResubmitXML", **kw)
        # no output wsaction
        response = self.binding.Receive(LoanResubmitXMLSoapOut.typecode)
        return response

Tags: nofromimportselfnoneurladdressrequest