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

时间:2013-09-23 08:01:01

标签: python mocking zsi

我有一个使用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

0 个答案:

没有答案