Esempio n. 1
0
    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')
Esempio n. 2
0
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_
Esempio n. 3
0
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
Esempio n. 4
0
@desc       :  资金管理流程自动化测试用例
"""

import json

from faker import Factory

from common.myCommon import Assertion
from common.myCommon.TestBaseCase import TestBaseCase
from xqkj.testAction import Xqkj_web_finance_consumptionAction as PlatformAction
from xqkj.testAction import loginAction

global_dict = loginAction.global_dict
fake = Factory().create('zh_CN')
# 资方名
FundSidename = fake.name() + '资方名' + loginAction.sign
# 资金包名
FundPackagename = fake.name() + '资金包名' + loginAction.sign


class testXqkj_web_finance_consumption_003_Fundside(TestBaseCase):
    def test_01_api_78dk_platform_fund_fundSide_saveFundSide_is_none(self):
        # 添加资方 ,name为空
        res = PlatformAction.test_api_78dk_platform_fund_fundSide_saveFundSide(
            '', 'enabled')
        Assertion.verity(json.loads(res)['code'], '20000')
        Assertion.verity(json.loads(res)['msg'], 'name不能为空!')

    # def test_02_api_78dk_platform_fund_fundSide_saveFundSide_256name(self):
    #     # 添加资方 ,name为空
    #     res = PlatformAction.test_api_78dk_platform_fund_fundSide_saveFundSide(''.join(fake.words(nb=128)), 'enabled')
Esempio n. 5
0
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()))
Esempio n. 6
0
# 导入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)))
def name():
    """Fake name generator."""
    fake = Factory().create('en_US')
    while True:
        yield (fake.name(), fake.address(),)
Esempio n. 8
0
# -*- 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,
Esempio n. 10
0
"""

import json
import unittest

from faker import Factory

from common.myCommon import Assertion, TimeFormat
from common.myCommon.TestBaseCase import TestBaseCase
from common.myFile import MockData
from ymjry.testAction import WebAction
from ymjry.testAction import loginAction
from ymjry.testAction import specialAction

fake = Factory().create('zh_CN')
bd_name = loginAction.sign + fake.name()
email = loginAction.sign + fake.email()
mobile = MockData.phone(11)
bd_name1 = loginAction.sign + fake.name()
email1 = loginAction.sign + fake.email()
mobile1 = MockData.phone(11)


class test_021_web_ombd(TestBaseCase):
    def test_001_api_78dk_platform_om_bd_addBdInfo_channeluuid_none(self):
        """
        BD新增 渠道uuid 为空
        :return:
        """
        res = WebAction.test_api_78dk_platform_om_bd_addBdInfo(channeluuid='',
                                                               email=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
Esempio n. 12
0
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='',
                                                     sysroleuuid='')