wholesale jewelry sterling silver 925
1 thought on “wholesale jewelry sterling silver 925 Which module of python can do interface testing”
Leave a Comment
You must be logged in to post a comment.
wholesale jewelry sterling silver 925
You must be logged in to post a comment.
wholesale jewelry pieces Python interface test
1. Install Python environment
2. Download python IDE (Pycharm)
Note:
requests are Python to give the HTTP client library, which is similar to Urllib2. Then why use requests and URLLIB2? The official document is said:
Python's standard library Urllib2 provides most of the HTTP functions required, but the API is too against the sky. A simple function requires a lot of code. Requests is relatively simple and can be implemented with less code.
3. Download and install the third -party module of Requests
The interface test below
It use requests to first quote
[python] view plain
Import requests
[python] View plain
# Analysis of JSON needs
[python] view plain
Import json
[python] view plain
# URL: interface address
[python] view plain
# data: The data required by the interface
[python] view plain
# headers: The headers data passed required for the interface n [python] view view play
# Files: If you need to upload files in the interface, you need to use this parameter
[python] view play
r = requests.post (url, data = data, headers = headers)
[python] view plain
r = requests.post (url, data = data, headers = headers, files = files)
[python] view plain n# Data information and parsing (if you return in JSON format)
[python] View plain
json_data = json.loads (R.TExt)
[python] View plain
me I have been writing 20 interfaces for testing in this way. Suddenly I found that there seems to be a lot of duplicate code. Can I encapsulate the duplicate content?
[python] View plain
The packaging is as follows:
[python] view plain
basics_requests.py n [python] View plain
import reviews
Import json
#xx_url: The interface is connected to URL
#data: The data that needs to be passed by the interface data (the data format is generally)
#headers The data format is generally)
#variable: The parameter field section (data format is list)
n n class basics ():
# initialization
# (Self, xx_url, data, headers, variable):
seld.xx_url = xx_url
seld.data = data
self.Headers
seld.variable = variable r r r r r r r r r r
DEF (Self):
# Initize the post request
url_data = requests.post (self.xx_url, data = seld.data, headers = selders)
# Turn to json format
data_json = json.loads (url_data.text)
# Change the parameter value in the request
if self.Variable! :
snelf.headers [i] = data_json [i.lower ()]
# Stay the request data and headers into the list
dispct_data = {data_json: data_json, headers: self. headers}
Return dic_data
Calling the packaging method:
[python] View plain
test.py n [python] view play
basics_re Quests
[python] view plain
basics_requests.basics (url, row_data, headers, variable). ()
[python] view plain.