栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

接口自动化测试之随机生成手机号并进行数据库校验

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

接口自动化测试之随机生成手机号并进行数据库校验

接口自动化测试之随机生成手机号并进行数据库校验

文章目录
    • 一、python 生成随机手机号
    • 二、数据库校验

一、python 生成随机手机号

代码如下(示例):

#不使用真实号段
import random
from Common.com_db import db
def __generator_phone():
    p='1'
    for i in range(0,10):#生成后10位
        p +=str(random.randint(0,9))#生成0-9随机数
    # print(p)
    return p
print(__generator_phone())

#使用真实号段

p=[178,180,182,156,130,134,136,137,147,139,155]
def __phone():
    index=random.randint(0,len(p)-1)
    phone=str(p[index])
    for i in range(0,8):#生成后8位
        phone+=str(random.randint(0,9))#生成0-9随机数
    # print(phone)
    return phone
二、数据库校验
def get_newphone():
    #连接数据库
    while True:
        #1、生成手机号
        #phone = __phone()
        phone=__generator_phone()
        #2、校验数据库是否存在,存在则重新生成
        try:
            count=db.get_count('select * from futureloan.member where mobile_phone="{}"'.format(phone))
            if count == 0:#手机号码没有在数据库查到,表示未注册的手机号
                db.close()
                print('手机号未注册')
            return phone
        except:
            print('手机号生成有误')
            raise
new_phone=get_newphone()
print(new_phone)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/269604.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号