zoukankan      html  css  js  c++  java
  • python测接口

    import requests
    import unittest
    import HTMLTestRunner
    
    
    class interface(unittest.TestCase):
        def setUp(self):
            pass
        def test_case1(self):
            url = 'http://www.baidu.com' #百度
            url1=url+'/a/b/c'            #路径
            req={ "transaction": {   # 传参
                    "header": {
                        "msg": {
                            "msgCd": "a",
                            "sndTm": "b",
                            "rcvAppCd": "c",
                            "sndAppCd": "d",
                            "sndDt": " e",
                            "seqNb": "f"
                        },
                        "ver": "g"
                    }
                    }}}
            re=requests.post(url1,None,req)     #发出请求,返回json
            re1=re.json()                       #json转换为字典
            re2=str(re1)                        #字典转换成字符串
    
            a0=True
            if '调用服务成功' in re2:
                a0=True
            else:
                a0=False
            self.assertEqual(a0,True)
            return re1
    
        def test_case2(self):
            case1=interface()
            mm=case1.test_case1()
            m=mm['transaction']['body']['response']['salesList']
            s=''
            for i in range(len(m)):
                s1 = '{"salesNo":"' + m[i]['salesNo'] + '","' + 'strNo":"' + m[i]['strNo'] + '","' + 'marNo":"' + m[i][
                    'marNo'] + '"}'
                if i == len(m) - 1:
                    s = s + s1
                else:
                    s = s + s1 + ','
            print(s)
            url22='/a/b/c1'
            req2_1 = {
                    "transaction": {
                        "header": {
                            "msg": {
                                "msgCd": "a",
                                "sndTm": "b",
                                "rcvAppCd": "c",
                                "sndAppCd": "d",
                                "sndDt": "e",
                                "seqNb": "f"
                            },
                            "ver": "g"
                        },
                        "body": {
                            "request": {
                                "areaMgrNo": "h",
                                "optType": "i",
                                "bindRelaList": s   #拼装的字符串
                            }
                        }
                    }
                }
            print(req2_1)
            re_1 = requests.post(url22,None,req2_1)
            print(re_1)
    
          #  re1_1 = re_1.json()  # json转换为字典
          #  re2_1 = str(re1_1)  # 字典转换成字符串
          #  print(re2_1)
            # a0 = True
            # if '调用服务成功' in re2_1:
            #     a0 = True
            # else:
            #     a0 = False
            # self.assertEqual(a0, True)
    
    if __name__=='__main__':
       unittest.main() 
      
     
    

      

  • 相关阅读:
    thinkphp自动映射分析
    thinkphp自动创建数据对象分析
    html模板输头部出现"&#65279"
    register_shutdown_function 函数详解
    mcrypt加密以及解密过程
    SVN不能解锁,报错:没有匹配的可用锁令牌的解决方法
    微信公众平台JSSDK开发
    PHP的UTF-8中文转拼音处理类
    PHP中文转拼音函数
    php生成mysql数据字典
  • 原文地址:https://www.cnblogs.com/ceshixuexi/p/7803569.html
Copyright © 2011-2022 走看看