code block
Import xlrd
Import UnitTest
Import requestsJson
ClassTest (unittest. TestCase):
DefDuqu (Self, filename=R ' E:\test\project\test_case\test.xlsx '):# Read Excel File
data = Xlrd.open_workbook (filename)# Open the file and pass the parameters to data
Table = Data.sheets () [0]# get Excel files in indexed order
parameter = Table.row_values (1)# Get the entire row of data get Excel second row of data
Jsoninfo =Eval (parameter[3])# because the parameter variable type is str needs to be converted to dict with the Eval function
URL =' HTTP//base URL ' + parameter[2]# Base address plus Test interface path
Return URL, parameter[1], Jsoninfo
DefTest_requests (Self):
Auth =Self.duqu ()# Call the Duqu function
Head = {
"Platform":"ios",
"Xnserver":"Aio-app-server",
"Version":"1.0.0",
"Content-type":"Application/json"
}
# Requests Library as interface core, incoming url,post request, JSON parameter
res = Requests.request ("%s"% auth[1], auth[0], json=auth[2],headers=head)
self.assertequal (Res.status_code, $ ) # assert code equals 200
Self.assertnotin (Res.text, ' ret ': 0 ')
If __name__==' __main__ ':
Unittest.main ()
Test.xlsx
Simply use the Requests+python2 interface test to read Excel to complete the interface test