91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

接口測試的幾種組織形式

發布時間:2020-06-01 13:34:24 來源:網絡 閱讀:486 作者:qq5a16e6241946e 欄目:編程語言

注冊接口測試

1、單個接口測試
#encoding=utf-8
import requests
import json

data = {'username': 'test001', 'password': 'wulaoshi12345', 'email': 'wulaoshi@qq.com'}

data = json.dumps(data)

res =  requests.post('http://39.106.41.11:8080/register/',data)
print(res.text)
print(res.status_code)
print(res.json())

2、單個接口帶斷言
#encoding=utf-8
import requests
import json
import re

pattern = re.compile(r"{'code': '00', 'userid': \d+}")
data = {'username': 'test003', 'password': 'wulaoshi12345', 'email': 'wulaoshi@qq.com'}

data = json.dumps(data)

res =  requests.post('http://39.106.41.11:8080/register/',data)

print(res.text)
print(res.status_code)
print(res.json())
print(str(res.json()))
assert pattern.match(str(res.json()))

3、使用隨機參數
#encoding=utf-8
import requests
import json,random
import re,string

username = [string.ascii_letters[random.randint(0,25)] for i in range(8)]
username = "".join(username)

pattern = re.compile(r"{'code': '00', 'userid': \d+}")
data = {'username': username, 'password': 'wulaoshi12345', 'email': 'wulaoshi@qq.com'}

data = json.dumps(data)

res =  requests.post('http://39.106.41.11:8080/register/',data)

print(res.text)
print(res.status_code)
print(res.json())
print(str(res.json()))
assert pattern.match(str(res.json()))

4、使用文件的的唯一數字參數使用戶唯一
#encoding=utf-8
import requests
import json,random
import re,string

with open("e:\\python\\c.txt","r+") as file_obj:
    username = file_obj.read().strip()
    print(username)
    file_obj.seek(0,0)
    file_obj.write(str(int(username) + 1))

username = "hhq" + username

pattern = re.compile(r"{'code': '00', 'userid': \d+}")
data = {'username': username, 'password': 'wulaoshi12345', 'email': 'wulaoshi@qq.com'}

data = json.dumps(data)

res =  requests.post('http://39.106.41.11:8080/register/',data)

print(res.text)
print(res.status_code)
print(res.json())
print(str(res.json()))
assert pattern.match(str(res.json()))

5、封裝常用函數
#encoding=utf-8
import requests
import json,random
import re,string

def post_request(url,data):
    res =  requests.post(url,data)
    return res

def get_response(res):
    print(res.text)
    print(res.status_code)
    print(res.json())
    print(str(res.json()))

def assert_response(res):
    pattern = re.compile(r"{'code': '00', 'userid': \d+}")

    assert pattern.match(str(res.json()))

with open("e:\\python\\c.txt","r+") as file_obj:
    username = file_obj.read().strip()
    print(username)
    file_obj.seek(0,0)
    file_obj.write(str(int(username) + 1))

username = "hhq" + username

url = 'http://39.106.41.11:8080/register/'
data = {'username': username, 'password': 'wulaoshi12345', 'email': 'wulaoshi@qq.com'}
data = json.dumps(data)

res = post_request(url,data)

get_response(res)

assert_response(res)

6、配置數據和程序的分離
Conf.py

url = 'http://39.106.41.11'
port = 8080
path = "register"

request_url = url + ":" + str(port) + "/" + path + "/"

#encoding=utf-8
import requests
import json,random
import re,string
from conf import *

def post_request(url,data):
    res =  requests.post(url,data)
    return res

def get_response(res):
    print(res.text)
    print(res.status_code)
    print(res.json())
    print(str(res.json()))

def assert_response(res):
    pattern = re.compile(r"{'code': '00', 'userid': \d+}")

    assert pattern.match(str(res.json()))

with open("e:\\python\\c.txt","r+") as file_obj:
    username = file_obj.read().strip()
    print(username)
    file_obj.seek(0,0)
    file_obj.write(str(int(username) + 1))

username = "hhq" + username

data = {'username': username, 'password': 'wulaoshi12345', 'email': 'wulaoshi@qq.com'}
data = json.dumps(data)

res = post_request(request_url,data)

get_response(res)

assert_response(res)

7、配置數據、測試數據和程序的分離
Conf.py

url = 'http://39.106.41.11'
port = 8080
path = "register"

request_url = url + ":" + str(port) + "/" + path + "/"

Data.txt

{'username': username, 'password': 'wulaoshi12345', 'email': 'wulaoshi@qq.com'}|r"{'code': '00', 'userid': \d+}"

#encoding=utf-8
import requests
import json,random
import re,string
from conf import *

def post_request(url,data):
    res =  requests.post(url,data)
    return res

def get_response(res):
    print(res.text)
    print(res.status_code)
    print(res.json())
    print(str(res.json()))

def assert_response(res,reg_pattern):
    pattern = re.compile(reg_pattern)
    assert pattern.match(str(res.json()))

with open("e:\\python\\c.txt","r+") as file_obj:
    uniquenumber= file_obj.read().strip()
    print(username)
    file_obj.seek(0,0)
    file_obj.write(str(int(username) + 1))

username = "hhq" + uniquenumber

with open("e:\\python\\data.txt","r") as fp:
     line = fp.readline().strip()
     #數據從文件讀出全部是字符串,需要獲取原類型
     data = eval(line.split("|")[0])
     #這里是把{'username': username, 'password': 'wulaoshi12345', 、
     #'email': 'wulaoshi@qq.com'}賦值給data,以上的username會自動傳入
     reg_pattern = eval(line.split("|")[1])

data = json.dumps(data)
print(data)

res = post_request(request_url,data)

get_response(res)

assert_response(res,reg_pattern)
向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

农安县| 保定市| 浮山县| 虎林市| 从化市| 桑植县| 临泉县| 定远县| 禄丰县| 牡丹江市| 泗水县| 静乐县| 遂平县| 普定县| 万荣县| 金山区| 上饶市| 会同县| 贵德县| 临漳县| 双江| 山阴县| 陵川县| 乌兰察布市| 宜川县| 桑植县| 通州市| 连云港市| 扎兰屯市| 轮台县| 锡林浩特市| 繁峙县| 洱源县| 凤阳县| 大埔区| 福贡县| 二连浩特市| 财经| 宝应县| 开平市| 同仁县|