python測介面

來源:互聯網
上載者:User

標籤:gcd   bin   .com   字串   slist   type   port   main   tca   

import requestsimport unittestimport HTMLTestRunnerclass 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()    

  

python測介面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.