Web 介面測試 Python3

2021-10-07 13:55:33 字數 4761 閱讀 4558

#!/usr/bin/env/python3

# -*- coding:utf-8 -*-

'''author:leo

date&time:2020/2/24 and 17:29

project:python3

filename:tmp_comment.py

description:...

1.快速構造請求頭:

(.*?):(.*) "$1":"$2",

(.*?): (.*) # (.*) $1: "", # $3

(.*?): (.*), # (.*) $1: kwargs.get($1, ""), # $3

2.快速構建表頭注釋:(.*?)\s(.*) "$1":$1 #$2

3.批量去除注釋:#(.*) ""

'''import re

comment_path = "d:\mytest\python3\python3\...\sit\\testcase\\testui\comment_txt"

# 移除**內部注釋資訊

def remove_comment():

'''描述:移除**內部注釋資訊,去掉#後面的內容

舉例:# 注釋資訊

""@return: none

'''with open("d:\mytest\python3\python3\...\hb_config.py", "r+", encoding="utf-8") as f:

all = f.read().splitlines()

for i in all:

if "#" in str(i.strip(" ")):

i = re.sub(r'#(.*)', "", i)

print(i)

# 構建介面請求引數

def build_request_parameters():

'''描述:批量構建函式請求體body中的引數

舉例:token 登入授權碼

"token":kwargs.get("token", "") # 登入授權碼

@return: none

'''with open(comment_path, "r+", encoding="gbk") as f:

all = f.read().splitlines()

str_all = ""

for i in all:

i = re.sub(r'(.*?)\s(.*)', r'"\1": kwargs.get("\1", ""), # \2', i)

str_all = str_all + i + "\n"

print(str_all)

# with open(r"d:\mytest\python3\python3\...\testfile\tmp1", "w+", encoding="gbk") as ff:

# ff.write(str_all)

# return str_all

# 構建函式的預設引數

def build_default_parameters():

"""描述:批量構建函式的預設引數

舉例:"token": kwargs.get("token", ""), # 登入授權碼

"username": kwargs.get("username", ""), # 姓名

token=none, username=none

@return: none

"""with open(comment_path, "r+", encoding="gbk") as f:

all = f.read().splitlines()

newstr = ""

for i in all:

if ":" in i and "[" not in i and "" not in i:

# i = i.split(',')[0].strip().split(":")[1].strip()

i = i.split(":")[0].strip(" ").replace('"', "")

newstr = newstr+i+"=none, "

print(newstr)

def buile_comment():

import ast

"""描述:批量構建函式的預設引數

舉例:0 - 僅鑑權

1 - 僅登記

2 - 鑑權並登記

(0-僅鑑權, 1-僅登記, 2-鑑權並登記)

@return: none

"""with open(comment_path, "r+", encoding="gbk") as f:

all = f.read().splitlines()

user_str = ""

for i in all:

# i = f"=user_dic[''], "

i = "".join(i.split()) + ", "

user_str = user_str + i

user_str = "("+user_str[0:-2]+")"

print(user_str)

# build_request_parameters() # 快速構建介面預設引數

# build_default_parameters() # 快速構建請求引數

buile_comment() # 快速注釋列舉

#!/usr/bin/env/python3

# -*- coding:utf-8 -*-

'''author:leo

date&time:2020/6/28 and 10:30

project:python3

filename:

description:

1.介面測試,單介面模板

'''import requests, time, random, linecache, os, re, datetime, json, sys, ast

from sit.library.basic import basic

# 單個業務測試類

class test():

# 初始化靜態引數

def __init__(self):

self.logtime = time.strftime('%y%m%d_%h:%m:%s', time.localtime(time.time()))

self.curtime = time.strftime('%y%m%d %h%m%s', time.localtime(time.time()))

self.nowdate_8, self.nowtime_6, self.random_3 = self.curtime.split(" ")[0], self.curtime.split(" ")[1], str(random.randint(100, 999))

# 1.test

def test(self, *args, **kwargs):

message = "test"

url = "/v1/customerlogin/test"

payload =

}res = basic().basic_runapi(message, url, headers, payload, token=kwargs.get("token", ""))

return res

# 2.test

def test(self, *args, **kwargs):

message = "test"

url = "/v1/customerlogin/test"

payload =

}res = basic().basic_runapi(message, url, headers, payload, token=kwargs.get("token", ""))

return res

# 2.test

def test(self, *args, **kwargs):

message = "test"

url = "/v1/customerlogin/test"

payload =

}res = basic().basic_runapi(message, url, headers, payload, token=kwargs.get("token", ""))

return res

# 4.test

def test(self, *args, **kwargs):

message = "test"

url = "/v1/customerlogin/test"

payload =

}res = basic().basic_runapi(message, url, headers, payload, token=kwargs.get("token", ""))

return res

# 5.原始介面測試

def tmp_test(self):

message = "3.2.2.25. 查詢貸款可選期限(實時介面)"

Web 介面測試 Python3

usr bin env python3 coding utf 8 author leo date time 2020 5 28 and 15 44 project python3 filename 20200528 email.py description qq郵件傳送 import smtplib...

python3介面程式設計 Python3程式設計技巧

in 1 fromrandom import randint in 2 data randint 10,10 for in range 10 in 3 data out 3 3,4,3,4,7,2,4,1,7,9 過濾列表中的負數 in 9 list filter lambda x x 0,data...

python3呼叫http介面

最近在寫python呼叫介面的服務,寫了乙個呼叫介面的函式,如下 param inputdata 單個樣本的輸入引數,是json格式的資料 return 單個樣本的探真查詢變數結果資料 呼叫介面 介面有正確的資料才讀入,否則為空 if res code 0000 res data json.load...