Simply use the Requests+python2 interface test to read Excel to complete the interface test

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.