From d4a80e71922c94d982be25170993b778de9e7f0e Mon Sep 17 00:00:00 2001 From: lyf Date: Mon, 29 Mar 2021 17:59:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E9=9A=8F=E6=9C=BA=E7=94=9F?= =?UTF-8?q?=E6=88=90ipv4=E5=92=8Cipv6=E5=92=8CURL=E5=85=B3=E9=94=AE?= =?UTF-8?q?=E5=AD=97=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 04-CustomLibrary/Custometest/Schema.py | 41 ++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/04-CustomLibrary/Custometest/Schema.py b/04-CustomLibrary/Custometest/Schema.py index 858b03b..ed6137a 100644 --- a/04-CustomLibrary/Custometest/Schema.py +++ b/04-CustomLibrary/Custometest/Schema.py @@ -4,8 +4,7 @@ import requests import random import json #import allure -number = random.randint(0,100000) -str = random.choice('abcdefghijklmnopqrstuvwxyz') + list = [] #请求schema接口得到返回数据,用于其他接口 def schema(schemauerl,token): @@ -22,6 +21,40 @@ def schema(schemauerl,token): #5、string要包含特殊字符 #6、给查询条件赋值,要给出边界和正常值 #7、IP(V4、V6)和URL要给出专门的方法生成 + +import ipaddress +#生成随机ipv4或ipv6 +MAX_IPV4 = ipaddress.IPv4Address._ALL_ONES # 2 ** 32 - 1 +MAX_IPV6 = ipaddress.IPv6Address._ALL_ONES # 2 ** 128 - 1 +def random_ipv4(): + return ipaddress.IPv4Address._string_from_ip_int( + random.randint(0, MAX_IPV4) + ) + +def random_ipv6(): + return ipaddress.IPv6Address._string_from_ip_int( + random.randint(0, MAX_IPV6) + ) + +from random import Random + +# 生成 12 位随机 URL 地址 +def randrom_url(): + str = '' + str1 = '' + chars = 'abcdefghijklmnopqrstuvwxyz0123456789' + chars1 = 'abcdefghijklmnopqrstuvwxyz0123456789!#$%^&*()' + length = len(chars) + length1 = len(chars1) + random = Random() + for x in range(random.randint(8,16)): + str += chars[random.randint(0,length - 1)] + for pp in range(random.randint(8,16)): + str1 += chars1[random.randint(0,length1 - 1)] + url = str[0:-5]+"." + str[0:-6] + "." + str[0:-7] + "/" + str1 + print(url) + return url + def Filter1(schemauerl,token): json_str = schema(schemauerl,token) print(type(json_str)) @@ -30,6 +63,10 @@ def Filter1(schemauerl,token): #获取不同属性支持的部不同操作 operator = json_str["data"]["doc"]["schema_query"]["references"]["operator"] for i in fields: + number = random.randint(-2147483648,2147483647) + maxnumber = 2147483647 + minnumber = -2147483648 + str = random.choice('abcdefghijklmnopqrstuvwxyz!@#$%^&*') name = i["name"] doc = i["doc"] #获取无任何特殊说明列: