Example unittest use management interface (data separator - Read excel)

1. Simple reading

# Coding. 8 = UTF- 

# invoke public methods package reading good excel 
from python_API.common.ReadExcel Import ReadExcel
 Import Requests
 Import JSON 

# acquired excel in the URL 
URL ReadExcel = ( " D: \\ dym.xls " , " Sheet1 " ) .getValue (1,1 ) 

# acquisition request excel embodiment of 
Method, ReadExcel = ( " D: \\ dym.xls " , " Sheet1 " ) .getValue (1,2 ) 

# acquired excel in header 
header = JSON .loads (ReadExcel ( " d: \\ dym.xls ","Sheet1").getValue(1,3))

#获取excel中的param
body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,4))

response = requests.request(Method,url,headers=header,params=body)
print response.json()

 

2. Add test report generation management framework unitest use cases

#coding=utf-8

from python_API.common.ReadExcel import ReadExcel
import requests
import json
import unittest
import HTMLTestRunner

class Test(unittest.TestCase):

    def setUp(self):
        self.url = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,1)
        self.Method = ReadExcel("d:\\dym.xls","Sheet1").getValue(1,2)
        self.header = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,3))

    def test01(self):
        body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(1,4))
        response = requests.request(self.Method,self.url,headers=self.header,params=body)
        self.assertEqual(response.json()["values"]["loginName"],"17779828887",msg="test01 error!")

    def test02(self):
        body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(2,4))
        response = requests.request(self.Method,self.url,headers=self.header,params=body)
        self.assertIn(u"错误",response.json()["errorMsg"],msg="test02 error!")

    def test03(self):
        body = json.loads(ReadExcel("d:\\dym.xls","Sheet1").getValue(3,4))
        response = requests.request(self.Method,self.url,headers=self.header,params=body)
        self.assertIn(u"错误",response.json()["errorMsg"],msg="test02 error!")

if __name__ == '__main__':
    suit = unittest.TestSuite()
    testcases = [Test("test01"),Test("test02"),Test("test03")]
    suit.addTests(testcases)
    dir = "D:\work_doc\pycharm2\python_API\\result\\report.html"
    path = open(dir,"wb")
    runner =HTMLTestRunner.HTMLTestRunner(stream=path,title="TestReport",description="test desc")
    runner.run(suit)

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/Mr-ZY/p/11877062.html