【Web_インタフェーステスト_Python 3_自動化生成四要素】氏名/身分証明書/銀行カード/携帯電話番号、インタフェーステスト準備作業の四要素生成、自動化テストケース
30224 ワード
#coding:utf-8
import random, datetime, time
from datetime import date
from datetime import timedelta
class Auth():
#
def generate_number_name(self, change_num="0001"):
'''
@param change_num: "0001", 4
@return: " "
'''
change_num = f"{change_num:0>4}"
old_list, new_list = list(change_num), []
str_num, str_chinese = "0123456789", " "
for i in old_list:
new_list.append(str_chinese[eval(i)])
# new_str = " " + "".join(new_list)
new_str = "".join(new_list)
# print(new_str)
return new_str
#
def generate_real_name(self):
num = random.randint(1, 1307)
name = [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",
" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", "Rapen", "Glgel", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " " ]
unicode_name = chr(random.randint(0x4e00, 0x9fbf))
return (" " + unicode_name + name[num][0] + name[num][1])
#
def check_last_idnum(self, id=None):
'''
@param id: 18
@return: True/False
'''
lis = list(id)
ten = ['X', 'x', 'Ⅹ']
ID = ["10" if i in ten else i for i in lis] # Ⅹ X 10
W = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
Checkcode = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
sum = 0
for i in range(17):
sum = sum + int(ID[i]) * W[i]
if Checkcode[sum % 11] == int(ID[17]):
print(' ')
return True
else:
print(' ')
return False
# 18 , 1000 87 ,
def generate_old_id(self):
'''
1. , 18
2. 6 ,8 ,3 ( , ),
3. ,
'''
area_id = str(510000)
year = str(random.randint(1990, 1999))
# +
da = date.today()+timedelta(days=random.randint(1, 366)) #
da = da.strftime('%m%d')
code = str(random.randrange(100, 999, 2)) # ,
id = area_id+year+da+code #
#
count = 0
weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2] #
checkcode = {'0': '1', '1': '0', '2': 'X', '3': '9', '4': '8', '5': '7', '6': '6', '7': '5', '8': '5', '9': '3', '10': '2'} #
for i in range(0, len(id)):
count = count + int(id[i])*weight[i]
check = checkcode[str(count%11)] #
id = id + check #
return id
# ( ) 18 ,1000 1000 ,
def generate_new_id(self):
''' , 18 , 6 ,8 ,3 ( , ), , '''
area_id = str(510000)
year = str(random.randint(1990, 1999))
# +
da = date.today()+timedelta(days=random.randint(1, 366)) #
da = da.strftime('%m%d')
code = str(random.randrange(100, 999, 2)) # # ( )
#
id = area_id+year+da+code
list_id = list(id)
ten = ['X', 'x', 'Ⅹ']
ID = ["10" if i in ten else i for i in list_id] # Ⅹ X 10
Weight = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
Checkcode = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2]
sum = 0
for i in range(17):
sum = sum + int(ID[i]) * Weight[i]
last_num = Checkcode[sum % 11]
id = str(id) + str(last_num) #
if "X" in id:
id = self.generate_new_id()
return id
else:
return id
# ( , )
def generate_oldbank_id(self):
''' , '''
head = '621284'
list1 = []
for i in range(11):
list1.append(random.choice('0123456'))
part = ''.join(list1)
end = '10'
code = head+part+end
return code
# ( , (Luhn ))
'''
if __name__ == '__main__':
for _ in range(10):
random_card_num = gen_card_num('621284', 19)
valid_result = check_luhn(random_card_num)
print('%s %s' % (random_card_num, valid_result))
'''
# (Luhn )
def check_luhn(self, card_num):
s = 0
card_num_length = len(card_num)
for _ in range(1, card_num_length + 1):
t = int(card_num[card_num_length - _])
if _ % 2 == 0:
t *= 2
s += t if t < 10 else t % 10 + t // 10
else:
s += t
return s % 10 == 0
def generate_newbank_id(self, start_with, total_num):
result = start_with
# N-1
while len(result) < total_num - 1:
result += str(random.randint(0, 9))
# N-1
s = 0
card_num_length = len(result)
for _ in range(2, card_num_length + 2):
t = int(result[card_num_length - _ + 1])
if _ % 2 == 0:
t *= 2
s += t if t < 10 else t % 10 + t // 10
else:
s += t
# , 10
t = 10 - s % 10
result += str(0 if t == 10 else t)
if Auth().check_luhn(result):
return result
else:
return " "
#
def generate_mobile(self):
tel = random.choice(['134', '139', '135', '150', '151', '157', '130', '132', '133', '153'])
list1 = []
for i in range(8):
list1.append(random.choice('0123456789'))
part = ''.join(list1)
mobile = tel+part
return mobile
# ,
def write_fourinfomation_txt(self,filename,user_info, mode="a+"):
filepath = "D:\Mytest\Python3\Python3\\"
# ( .txt, )
with open(filepath + f'{filename}', mode=mode, encoding="utf8") as wfile:
wfile.write(user_info)
wfile.write("
")
wfile.seek(0, 0)
new = wfile.read()
# print(str(new))
if __name__ == '__main__':
'''
now = datetime.datetime.now()
nowtime=str(now.strftime('%Y%m%d%H%M%S'))
logging.basicConfig(filename=os.path.join(os.getcwd(),' '+nowtime+'.txt'),level=logging.INFO)
for i in range(100):
logging.info(" =%s",Auth().id())
'''
def tmp(j=0):
logTime = time.strftime('%Y%m%d_%H:%M:%S', time.localtime(time.time()))
m = ""
dev, sit, uat, pre = "0", "1", "2", "3"
for i in range(1, 5000):
# idName = Auth().realname()
idName = Auth().generate_number_name(change_num=str(i))
idNo = Auth().generate_new_id()
idBank = Auth().generate_newbank_id('621284', 19)
# idMobile = Auth().generate_mobile()
idMobile = f"185{sit:0>2}{j:0>2}{i:0>4}" # dev:0,sit:1, 0, 5001
m = f"{idName}"+","+f"{idNo:<18}"+","+idBank+","+idMobile
# print(m)
Auth().write_fourinfomation_txt(f"2020_infoAutoID{j}.txt", str(m))
for n in range(11, 12, 1):
tmp(j=n)