def testAuthorization(self,host=None,headers=None,data=None,idcard=None,*args,**kwargs): if host: url="{}{}".format(metadata['url'][str(host)],metadata['path']['operatorauth']) else: url="{}{}".format(metadata['url']['79'],metadata['path']['operatorauth']) if headers : headers['Authorization']=mvar.get_value('auth') else: headers=metadata['headers'] headers['Authorization']=mvar.get_value('auth') if not data: data={"type":"1"} res=requests.post(url=url,headers=headers,data=data) # mock服务 if idcard: IDcode=idcard else: IDcode=str(metadata['IDcode']) mock_data={ "userId": IDcode, "outUniqueId": "{}".format(get_outUniqueId(host=host,id_code=IDcode)), "state": "report", "account": "15018312895", "accountType": "mobile", "search_id": "15371700453131388180" } mock_url=metadata['url']['mock_url'] resmock = requests.post(url=mock_url,headers=headers,data=mock_data) print("Test Authorization Method is run .......")
def test_staff(self,host=None): code=metadata['customerCode'] path1 = f'/v1/staff/{code}?nothing') path2 = '/v1/userinfo/staff' if host: url1=f"{metadata[str(host)]}{path1}" url1=f"{metadata[str(host)]}{path2}" print(f"测试服务器地址:{host},{url1}{url2}") else: url1="{}{}".format(metadata['url']['79'],path1) url1="{}{}".format(metadata['url']['79'],path2) print(f"测试服务器地址默认环境: {url1}{url2}") self.res=requests.get(url=url,) data = {"staffNo": code} if headers : headers['Authorization']=mvar.get_value('auth') self.headers=headers else: headers=metadata['headers'] headers['Authorization']=mvar.get_value('auth') self.headers=headers res = self.req.post(url=url, headers=self.headers, data=data) print(res.text)
def test_confirmation(self,idcare=None,name=None): if host: url=metadata[str(host)]+metadata['path']['ocr'] print(f"测试服务器地址:{host},{url}") else: url="{}{}".format(metadata['url']['79'],metadata['path']['ocr']) print(f"测试服务器地址默认环境: {url}") if headers : headers['Authorization']=mvar.get_value('auth') self.headers=headers else: headers=metadata['headers'] headers['Authorization']=mvar.get_value('auth') self.headers=headers if idcare: self.idcare=str(idcare) else: self.idcare=metadata['IDcode'] if name: self.name=str(name) else: self.name=metadata['name'] data = { "confirmation": 1, "idCardCode": self.idcare, "idCardName": self.name] }
def testTaobao(self,host=None,headers=None,data=None,idcard=None,*args,**kwargs): if host: url="{}{}".format(metadata['url'][str(host)],metadata['path']['taobao']) else: url="{}{}".format(metadata['url']['79'],metadata['path']['taobao']) print("淘宝认证:",url) if headers : headers['Authorization']=mvar.get_value('auth') else: headers=metadata['headers'] headers['Authorization']=mvar.get_value('auth') res = requests.post(url=url, headers=headers) print(res.text) if idcard: IDcode = idcard else: IDcode = str(metadata['IDcode']) print(IDcode) # 修改mock服务参数 urlparam='http://mockserver.hexindai.com/taobaoModify' dataparam={"Name":metadata['name'],'idCard':IDcode} respar= requests.post(urlparam, data=dataparam) print("修改数据:",respar.json()) # mock 服务 mock_url=metadata['url']['mock_url'] user_id=order_id=get_taobao(host=host, id_code=IDcode) noticeap={ "order_id":"{order_id}".format(order_id), "biz_bu":"taojinyun", "isol_apply_from":"taojinyun", "productId":"J20180130161546529P46", "user_id":"{user_id}".format(user_id) } mock_data={ "status_id":"206801336", "session":"cc1fa58e2f7c822b6fe37e58710de06e", "module":"taobao", "status":"2", "notice_attached_param":"{noticeap}".format(noticeap), "user_id":"{user_id}".format(user_id), } print(mock_data) resmock=requests.post(mock_url,mock_data) print(resmock)
def testoccupation(self,host=None,headers=None,data=None,*args,**kw): if host: url="{}{}".format(metadata['url'][str(host)],metadata['path']['Occupation']) else: url="{}{}".format(metadata['url']['79'],metadata['path']['Occupation']) if headers : headers['Authorization']=mvar.get_value('auth') else: headers=metadata['headers'] headers['Authorization']=mvar.get_value('auth') if not data: data=metadata['Occupation_data'] res=requests.post(url=url,headers=headers,data=data) print("Test Occupation Method is run .......")
def testZhifubao(self,host=None,headers=None,data=None,idcard=None,*args,**kwargs): if host: url="{}{}".format(metadata['url'][str(host)],metadata['path']['zhifubao']) else: url="{}{}".format(metadata['url']['79'],metadata['path']['zhifubao']) print("支付宝:",url) if headers : headers['Authorization']=mvar.get_value('auth') else: headers=metadata['headers'] headers['Authorization']=mvar.get_value('auth') res = requests.post(url=url, headers=headers) print(res.json()) if idcard: IDcode = idcard else: IDcode = str(metadata['IDcode']) print(IDcode) if not data: data={"type":"4"} res= requests.post(url=url,headers=headers,data=data) print(res.json()) # mock mock_data={ "state":"report", "accountType":"alipay", "account":"15018312895", "userId":"440803198903180315", "search_id":"15371700453131388180", "outUniqueId":"{}".format(get_zhifubao(host,IDcode)), } mock_url=metadata['url']['mock_url'] print(mock_data) resmock=requests.post(mock_url,mock_data) print(resmock)
def test_ocr(self,host=None,headers=None): os.chdir(sys.path[0] + '/case') if host: url=metadata[str(host)]+metadata['path']['ocr'] print(f"测试服务器地址:{host},{url}") else: url="{}{}".format(metadata['url']['79'],metadata['path']['ocr']) print(f"测试服务器地址默认环境: {url}") if headers : headers['Authorization']=mvar.get_value('auth') self.headers=headers else: headers=metadata['headers'] headers['Authorization']=mvar.get_value('auth') self.headers=headers with open('1.jpg', 'rb') as frontImage: with open('2.jpg', 'rb') as backImage: files = {'frontImage': frontImage, 'backImage': backImage} self.res = requests.post(url=url, headers=self.headers, files=files) if "idCardCode" in self.res.json(): logger.info("解析身份证成功... ...")
def testuserrelation(self,host=None,headers=None,data=None,*args,**kw): if host: url="{}{}".format(metadata['url'][str(host)],metadata['path']['UserRelation']) else: url="{}{}".format(metadata['url']['79'],metadata['path']['UserRelation']) if headers : headers['Authorization']=mvar.get_value('auth') else: headers=metadata['headers'] headers['Authorization']=mvar.get_value('auth') if not data: girl={"linkType":"1","menName":"王伊","menPhone":"18813601525","relationship":"配偶"} family={"linkType":"1","menName":"王梦","menPhone":"13601528888","relationship":"父母"} friend={"linkType":"3","menName":"心飞","menPhone":"13601501252","relationship":"朋友"} colleague={"linkType":"3","menName":"王蛋蛋","menPhone":"13609120525","relationship":"同事"} # contacts =f'[{girl},{family},{friend},{colleague}]'.replace('\'','\"').replace(' ','') contacts ='[{},{},{},{}]'.format(girl,family,friend,colleague) contacts=contacts.replace('\'','\"').replace(' ','') data={"contacts":contacts,"emergencyContactKnow":"1","familyKnow":"1",} res=requests.post(url=url,headers=headers,data=data) print("Test User Relation Method is run .......")