def convertUrlParamToJson(self, urlParam, tupeKey="goodsList"): pjson = {} params = parseRequestParam(urlParam) for k in params: v = params[k] tjson = pjson try: i = k.index("[") key, k = k[0:i], k[i + 1:] except: pjson[k] = v continue keys = [key] + k.replace("][", ",").replace("[", "").replace( "]", "").split(",") for i in range(len(keys)): key = keys[i] if i < len(keys) - 1: try: tjson = tjson[key] except: if type(tjson) == list: key = int(key) while len(tjson) <= key: tjson.append({}) tjson = tjson[key] else: tjson[key] = [] if tupeKey.__contains__( key) else {} tjson = tjson[key] else: tjson[key] = v return pjson
def addUrlMock(self, url, param, resp, isdelete='false'): if self.urlmockdata is None: self.urlmockdata = {} if isdelete == "true": try: self.urlmockdata.__delitem__(url) except: pass else: self.urlmockdata[url] = {'p': parseRequestParam(param), 'd': resp} return self.urlmockdata.keys()
def _getMockkey(self, reqPath, reqParam): reqPath = reqPath.split("?")[0] if self.urlmockdata.__contains__(reqPath): param = parseRequestParam(reqParam) urlmock = self.urlmockdata[reqPath] uparam = urlmock['p'] isMatch = True for p in uparam.keys(): if not (param.__contains__(p) and uparam[p] == param[p]): isMatch = False break if isMatch: return urlmock
def addUrlMock(self, url, param, resp, status=200, wait=0, isdelete='false'): if self.urlmockdata is None: self.urlmockdata = {} if isdelete == "true": try: self.urlmockdata.__delitem__(url) except: pass else: self.urlmockdata[url] = { 'p': parseRequestParam(param), 'd': resp, 's': int(status), 'w': float(wait) } return self.urlmockdata.keys()