class mockDataGenerator(): def __init__(self, language): self.fake = Factory().create(language) def random_phone_number(self): return self.fake.phone_number() def random_name(self): return self.fake.name() def random_address(self): return self.fake.addres() def random_email(self): return self.fake.email() def random_ipv4(self): return self.fake.ipv4() def random_str(self, min_chars=0, max_chars=8): return self.fake.pystr(min_chars=min_chars, max_chars=max_chars) def random_text(self): return self.fake.text() def random_timestamp(self): return self.fake.unix_time(end_datetime=None) def random_int(self): return self.fake.pyint() def random_bool(self): return self.fake.pybool() def random_description(self): return self.fake.paragraph(nb_sentences=3, variable_nb_sentences=True, ext_word_list=None) def random_title(self): return self.fake.sentence(nb_words=6, variable_nb_words=True, ext_word_list=None) def random_type(self): i = random.randint(0, 10) if i == 0: type_ = '前端' else: type_ = '后端' return type_
def get_some_things(self, faker_type: str = "" or list) -> str or int or float: """ 根据faker type生成响应数据,并返回结果 :param faker_type: mobile, farm, name, shop, int, float :return: """ data = "" fake = Factory().create('zh_CN') # 传入为list时,随机返回list中的一个值 if isinstance(faker_type, list): return random.choice(faker_type) elif isinstance(faker_type, str): # 若传入时下列关键字,返回对应的值 record = faker_type.lower() if record == 'mobile': data = fake.phone_number() self.L.info("随机生成手机号:%s" % data) elif record == 'farm': data = fake.company_prefix() + "的" + fake.name() + "在中国" + fake.city() + "的农场" self.L.info("随机生成农场名:%s" % data) elif record == 'name': data = fake.name() self.L.info("随机生成用户民:%s" % data) elif record == 'shop': data = fake.company() self.L.info("随机生成店铺名:%s" % data) elif record == 'integer': data = random.randint(1, 100) self.L.info("随机生成整数:%s" % data) elif record == 'decimal': data = random.uniform(1, 50) self.L.info("随机生成小数:%s" % data) elif record == 'text': data = (fake.text().replace("\n", " "))[:20] self.L.info("随机20位字符串:%s" % data) elif record == 'address': data = fake.address() self.L.info("随机生成地址:%s" % data) else: data = faker_type return data # if __name__ == '__main__': # f = KeyFaker() # f.get_some_things('farm')
class Generator: def __init__(self): self.fake = Factory().create('zh_CN') def random_phone_number(self): """随机手机号""" return self.fake.phone_number() def random_name(self): """随机姓名""" return self.fake.name() def random_address(self): """随机地址""" return self.fake.address() def random_email(self): """随机email""" return self.fake.email() def random_ipv4(self): """随机IPV4地址""" return self.fake.ipv4() def random_str(self, min_chars=0, max_chars=8): """长度在最大值与最小值之间的随机字符串""" return self.fake.pystr(min_chars=min_chars, max_chars=max_chars) def factory_generate_ids(self, starting_id=1, increment=1): """ 返回一个生成器函数,调用这个函数产生生成器,从starting_id开始,步长为increment。 """ def generate_started_ids(): val = starting_id local_increment = increment while True: yield val val += local_increment return generate_started_ids def factory_choice_generator(self, values): """ 返回一个生成器函数,调用这个函数产生生成器,从给定的list中随机取一项。 """ def choice_generator(): my_list = list(values) # rand = random.Random() while True: yield random.choice(my_list) return choice_generator
def f_gen_user(): fake = Factory().create('zh_CN') #starttime= datetime.datetime.now() li = [] tp = () num = 0 v_batch = 100 while num < v_batch: num += 1 user_info = (fake.profile(fields=None, sex=None)) v_user = user_info['username'] v_pass = fake.md5(raw_output=False) v_name = user_info['name'] v_sex = user_info['sex'] v_mobile = fake.phone_number() v_address = user_info['address'] v_mail = user_info['mail'] v_ssn = user_info['ssn'] v_birthdate = user_info['birthdate'] tp = (v_user,v_pass,v_name,v_sex,v_mobile,v_address,v_birthdate,v_mail,v_ssn) li.append(tp) #rint(count) return li
from hmpt.testAction import AppAction from hmpt.testAction import loginAction fake = Factory().create('zh_CN') company_city = '510100' company_city_name = '成都市' company_detail = '天府软件园B区' company_name = fake.company() + loginAction.sign company_province = '510000' company_province_name = '四川省' company_region = '510108' company_region_name = '成华区' datum_type_income_id = '25' datum_type_worktime_id = '93' position = fake.job() + loginAction.sign work_phone = fake.phone_number() contract_uuid = loginAction.global_dict.get('contract_uuid') class test_015_app_process_WorkInfo(TestBaseCase): def test_001_api_78dk_app_process_saveWorkInfo(self): """ 保存工作信息 :return: """ res = json.loads( AppAction.test_api_78dk_app_process_saveWorkInfo( companycity=company_city, companycityname=company_city_name, companydetail=company_detail, companyname=company_name,
from faker import Factory if __name__ == '__main__': """ 模拟数据生成 """ fake = Factory().create('zh_CN') for i in range(10): print("{name} {phone} {address} {email}".format( name=fake.name(), phone=fake.phone_number(), address=fake.address(), email=fake.email()))
# 导入faker模块 from faker import Factory fake = Factory().create(locale="zh_CN") # print(dir(fake)) for i in range(1, 11): print("第{0}次随机产生的数据:".format(i)) print("用户姓名:{0}".format(fake.name())) print("用户名:{0}".format(fake.user_name())) print("密码:{0}".format(fake.password())) print("电子信箱:{0}".format(fake.email())) print("电话号码:{0}".format(fake.phone_number())) print("住址:{0}".format(fake.address())) print("所在城市:{0}".format(fake.city())) print("段落:{0}".format(fake.paragraph())) print("文本:{0}".format(fake.text())) print("IPv4:{0}".format(fake.ipv4())) print("网址:{0}".format(fake.url())) print("指定长度的字符串:{0}".format(fake.pystr(min_chars=6, max_chars=12)))
""" import json import unittest from faker import Factory from common.myCommon import Assertion from common.myCommon.TestBaseCase import TestBaseCase from mjjry.query import xqkj_query from mjjry.testAction import AppAction from mjjry.testAction import loginAction fake = Factory().create('zh_CN') bank_card_no = '6214832019120836' bill_email = loginAction.sign + fake.email() bank_card_mobile = fake.phone_number() class test_013_app_process_BankCardInfo(TestBaseCase): def test_001_api_78dk_app_process_getSupportBanks(self): """ 查询支持银行(弹窗描述) :return: """ res = json.loads(AppAction.test_api_78dk_app_process_getSupportBanks()) Assertion.verity(res['code'], '10000') def test_002_api_78dk_app_process_getBankCardInfo(self): """ 查询绑定的银行卡列表 :return:
# -*- coding: utf-8 -*- import os import random from faker import Factory from run_path import test_report_path fake = Factory().create('zh_CN') print(fake.phone_number()) print(fake.name()) print(fake.address()) print(fake.email()) report = os.path.join(test_report_path(), '59017-12工资单.xls') os.remove(report)
fake = Factory().create('zh_CN') email = fake.email() datum_type_education_id = '8' datum_type_housing_id = '15' datum_type_marry_id = '18' live_city = '510100' live_city_name = '成都市' live_detail = '天府软件园B区' live_province = '510000' live_province_name = '四川省' live_region = '510106' live_region_name = '金牛区' contactlist = [{ "datumTypeContactId": i + 1, "name": fake.name(), "phone": fake.phone_number() } for i in range(2)] contract_uuid = loginAction.global_dict.get('contract_uuid') class test_014_app_process_PersonInfo(TestBaseCase): def test_001_api_78dk_app_process_savePersonInfo(self): """ 保存基本信息 :return: """ res = json.loads( AppAction.test_api_78dk_app_process_savePersonInfo( contactlist=contactlist, datumtypeeducationid=datum_type_education_id, datumtypehousingid=datum_type_housing_id,
from faker import Factory from common.myCommon import Assertion from common.myCommon.TestBaseCase import TestBaseCase from common.mydb import MysqlClent from xqkj.testAction import PlatformAction from xqkj.testAction import loginAction from xqkj.testAction import specialAction fake = Factory().create('zh_CN') name = fake.name_male() name = loginAction.sign + name idcard = fake.ssn(min_age=18, max_age=20) email = fake.email() phone = fake.phone_number() # 修改用户信息 name3 = fake.name_male() name3 = loginAction.sign + 'modify' + name3 phone3 = fake.phone_number() email3 = fake.email() # 新增用户测试--非email name4 = fake.name_male() name4 = loginAction.sign + 'mail' + name4 phone4 = fake.phone_number() email4 = fake.email()
class TestdataGenerator(object): """一些生成器方法,生成随机数,手机号,以及连续数字等""" def __init__(self): self.fake = Factory().create('zh_CN') def random_phone_number(self): """随机手机号""" return self.fake.phone_number() def random_name(self): """随机姓名""" return self.fake.name() def random_address(self): """随机地址""" return self.fake.address() def random_email(self): """随机email""" return self.fake.email() def random_ipv4(self): """随机IPV4地址""" return self.fake.ipv4() def random_str(self, min_chars=0, max_chars=8): """长度在最大值与最小值之间的随机字符串,只包含a-zA-Z字母""" return self.fake.pystr(min_chars=min_chars, max_chars=max_chars) def random_int(self, min_value=0, max_value=9999, exclude=None): """返回[min_value, max_value]范围内的一随机数,可排除范围内任意数""" if exclude is not None: if not isinstance(exclude, list): return "exclude must a list" else: exclude = list() while True: value = self.fake.pyint(min_value=min_value, max_value=max_value) if value not in exclude: return value def random_letter_digit_str(self, min_chars=0, max_chars=8): """长度在最大值与最小值之间的随机字符串,只包含a-zA-Z字母和0-9数字""" if min_chars is None: return "".join(self.random_letters_digits(length=max_chars)) else: assert ( max_chars >= min_chars ), "Maximum length must be greater than or equal to minium length" return "".join( self.random_letters_digits(length=random.randint( min_chars, max_chars), ), ) def random_letters_digits(self, length=16): """返回一随机字母、数字字符串(a-z 、A-Z 、0-9).""" return self.fake.random_choices( getattr(string, 'letters', string.ascii_letters + string.digits), length=length, ) def random_punctuation_str(self, min_chars=0, max_chars=8): """返回长度在最大值与最小值之间的随机字符串,只包含英文标点符号""" if min_chars is None: return "".join(self.random_punctuation(length=max_chars)) else: assert ( max_chars >= min_chars ), "Maximum length must be greater than or equal to minium length" return "".join( self.random_punctuation(length=random.randint( min_chars, max_chars), ), ) def random_punctuation(self, length=16): """返回一随机英文标点符号""" return self.fake.random_choices( getattr(string, 'letters', string.punctuation), length=length, ) @classmethod def factory_generate_ids(cls, starting_id=1, increment=1): """ 返回一个生成器函数,调用这个函数产生生成器,从starting_id开始,步长为increment。 """ def generate_started_ids(): val = starting_id local_increment = increment while True: yield val val += local_increment return generate_started_ids @classmethod def factory_choice_generator(cls, values): """ 返回一个生成器函数,调用这个函数产生生成器,从给定的list中随机取一项。 """ def choice_generator(): my_list = list(values) while True: yield random.choice(my_list) return choice_generator
class DataGenerator(object): """随机数据生成器""" def __init__(self): self.fake = Factory().create('zh_CN') def random_phone_number(self): """ 随机手机号码 :return: """ return self.fake.phone_number() def random_name(self): """ 随机姓名 :return: """ return self.fake.name() def random_address(self): """ 随机地址 :return: """ return self.fake.address() def random_email(self): """ 随机email :return: """ return self.fake.email() def random_ipv4(self): """ 随机ip地址 :return: """ return self.fake.ipv4() def random_str(self, min_char=0, max_char=8): """ 随机字符,默认8个 :return: """ return self.fake.pystr(min_chars=min_char, max_chars=max_char) @staticmethod def random_chinese_characters(i=1): """随机中文汉字""" s = "" if i < 11: s = xeger.xeger(u"[\\u4e00-\\u9fa5]{}".format("{" + str(i) + "}")) else: j = i // 10 k = i % 10 while j > 0: a = xeger.xeger(u"[\\u4e00-\\u9fa5]{10}") s = s + a j -= 1 if j == 0: a = xeger.xeger( u"[\\u4e00-\\u9fa5]{}".format("{" + str(k) + "}")) s = s + a return s
import json import unittest from faker import Factory from common.myCommon import Assertion as ass from common.myCommon.TestBaseCase import TestBaseCase from easyloan.query import easyloan_query as eq from easyloan.testAction import Easyloan_webAction as ew, loginAction as la f = Factory().create('zh_CN') role_name = 'role' + la.sign addAdmin_email = la.sign + f.email() addAdmin_password = '******' addAdmin_phone = f.phone_number() addAdmin_name = la.sign + f.name() org_name = la.sign + f.company() org_address = la.sign + f.street_name() class testEasyloan_web_003_role(TestBaseCase): def test_001_api_78dk_web_role_queryRoleList(self): """ Time :2019-04-28 author : 罗林 desc : 分页查询 """ rs = ew.test_api_78dk_web_role_queryRoleList(currentpage=1, pagesize=10, codeno='',