当前位置: 首页>>代码示例>>Python>>正文


Python faker.Faker方法代码示例

本文整理汇总了Python中faker.Faker方法的典型用法代码示例。如果您正苦于以下问题:Python faker.Faker方法的具体用法?Python faker.Faker怎么用?Python faker.Faker使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在faker的用法示例。


在下文中一共展示了faker.Faker方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: choice

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def choice(self, field=None):
        assert field is not None, "The field parameter must be passed to the 'choice' method."
        choices = [c[0] for c in field.choices]
        return self.get_allowed_value(lambda: random.choice(choices), field)

    # Other attributes provided by 'Faker':
    # user_name
    # first_name
    # last_name
    # name
    # email
    # address
    # phonenumber
    # street_address
    # city
    # state
    # zip_code
    # company 
开发者ID:BetterWorks,项目名称:django-anonymizer,代码行数:20,代码来源:base.py

示例2: test_user_partial_update

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def test_user_partial_update(conf, requests_session, headers):
    # Create a new user
    user_data = create_new_user(requests_session, conf.getoption("server"), headers)

    # Update the user's first name
    fake = Faker()
    updated_data = {"first_name": fake.first_name()}
    response = requests_session.patch(
        urljoin(conf.getoption("server"), "/api/v3/user/{}/".format(user_data["id"])),
        headers=headers,
        data=updated_data,
    )
    assert response.status_code == 200
    assert_valid_schema(response.json())

    # Verify they match our expected values
    response = requests_session.get(
        urljoin(conf.getoption("server"), "/api/v3/user/{}".format(user_data["id"])),
        headers=headers,
    )
    assert response.status_code == 200
    assert_valid_schema(response.json())
    assert updated_data["first_name"] == response.json()["first_name"] 
开发者ID:mozilla,项目名称:normandy,代码行数:25,代码来源:test_user_partial_update.py

示例3: create_new_user

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def create_new_user(requests_session, server, headers):
    # Get a list of groups and grab the ID of the first one
    response = requests_session.get(urljoin(server, "/api/v3/group/"), headers=headers)
    group_id = response.json()["results"][0]["id"]
    group_name = response.json()["results"][0]["name"]
    fake = Faker()

    # Create a user, assigning them to the group we obtained
    user_data = {
        "first_name": fake.first_name(),
        "last_name": fake.last_name(),
        "email": fake.company_email(),
        "groups": {"id": group_id, "name": group_name},
    }
    response = requests_session.post(
        urljoin(server, "/api/v3/user/"), headers=headers, data=user_data
    )

    return {
        "id": response.json()["id"],
        "first_name": response.json()["first_name"],
        "last_name": response.json()["last_name"],
        "group_id": group_id,
    } 
开发者ID:mozilla,项目名称:normandy,代码行数:26,代码来源:helpers.py

示例4: test_user_update

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def test_user_update(conf, requests_session, headers):
    # Create a new user
    user_data = create_new_user(requests_session, conf.getoption("server"), headers)

    # Update the user's first and last names
    fake = Faker()
    updated_data = {"first_name": fake.first_name(), "last_name": fake.last_name()}
    response = requests_session.put(
        urljoin(conf.getoption("server"), "/api/v3/user/{}/".format(user_data["id"])),
        headers=headers,
        data=updated_data,
    )
    assert response.status_code == 200
    assert_valid_schema(response.json())

    # Verify they match our expected values
    response = requests_session.get(
        urljoin(conf.getoption("server"), "/api/v3/user/{}".format(user_data["id"])),
        headers=headers,
    )
    assert response.status_code == 200
    assert_valid_schema(response.json())
    assert updated_data["first_name"] == response.json()["first_name"]
    assert updated_data["last_name"] == response.json()["last_name"] 
开发者ID:mozilla,项目名称:normandy,代码行数:26,代码来源:test_user_update.py

示例5: test_user_create

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def test_user_create(conf, requests_session, headers):
    # Get a list of groups and grab the ID of the first one
    response = requests_session.get(
        urljoin(conf.getoption("server"), "/api/v3/group/"), headers=headers
    )
    assert response.status_code == 200
    assert_valid_schema(response.json())
    group_id = response.json()["results"][0]["id"]
    group_name = response.json()["results"][0]["name"]
    fake = Faker()

    # Create a user, assigning them to the group we obtained
    user_data = {
        "first_name": fake.first_name(),
        "last_name": fake.last_name(),
        "email": fake.company_email(),
        "groups": {"id": group_id, "name": group_name},
    }
    response = requests_session.post(
        urljoin(conf.getoption("server"), "/api/v3/user/"), headers=headers, data=user_data
    )
    assert response.status_code == 201, response.json()
    assert_valid_schema(response.json()) 
开发者ID:mozilla,项目名称:normandy,代码行数:25,代码来源:test_user_create.py

示例6: container

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def container(request, docker_client, tmpdir_factory):
    fake = Faker()
    obj = ContainerFactory(
        config__name='proxy_container_{0}_{1}_{2}'.format(fake.word(), fake.word(), os.environ.get('ST_JOB_ID', '')),  # pylint: disable=no-member
        config__docker_client=docker_client,
        config__image=request.config.getini('IMAGE'),
        config__environment={
            'ROOT_MOUNTPOINT': '/salt/src',
            'TOASTER_MOUNTPOINT': '/salt-toaster',
            'SALT_TESTS': '/salt/src/salt-2015.8.7/tests',
            'VERSION': 'sles12sp1',
        },
        config__salt_config=None,
        config__host_config=None
    )
    upload(obj, request.config.rootdir.parts()[-2].strpath, '/salt-toaster', tmpdir_factory)
    request.addfinalizer(obj.remove)
    return obj 
开发者ID:openSUSE,项目名称:salt-toaster,代码行数:20,代码来源:upstream.py

示例7: module_config

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def module_config(request):
    fake = Faker()
    return {
        "masters": [
            {
                "minions": [
                    {
                        "config": {
                            "container__config__name": 'minion_{0}_{1}_{2}'.format(fake.word(), fake.word(), os.environ.get('ST_JOB_ID', '')),  # pylint: disable=no-member
                            "container__config__image": (
                                request.config.getini('MINION_IMAGE') or
                                request.config.getini('IMAGE')
                            )
                        }
                    }
                ]
            }
        ]
    } 
开发者ID:openSUSE,项目名称:salt-toaster,代码行数:21,代码来源:conftest.py

示例8: proxy_server

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def proxy_server(request, salt_root, docker_client):
    fake = Faker()
    name = u'proxy_server_{0}_{1}_{2}'.format(fake.word(), fake.word(), os.environ.get('ST_JOB_ID', ''))  # pylint: disable=no-member
    command = 'python -m tests.scripts.proxy_server {0}'.format(PROXY_PORT)
    obj = ContainerFactory(
        config__image=request.config.getini('IMAGE'),
        config__command=command,
        config__name=name,
        config__salt_config=None,
        config__host_config=docker_client.create_host_config(
            binds={
                os.getcwd(): {
                    'bind': "/salt-toaster/",
                    'mode': 'rw'
                }
            }
        ),
        config__volumes=[os.getcwd()]
    )
    request.addfinalizer(obj.remove)
    return obj 
开发者ID:openSUSE,项目名称:salt-toaster,代码行数:23,代码来源:test_proxy.py

示例9: module_config

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def module_config(request, minion_id, proxy_server):
    fake = Faker()
    proxy_url = 'http://{0}:{1}'.format(proxy_server['ip'], PROXY_PORT)
    return {"masters": [{
        "config": {
            "container__config__salt_config__pillar": {
                "top": {"base": {minion_id: ["proxy"]}},
                "proxy": {
                    "proxy": {"proxytype": "rest_sample", "url": proxy_url}
                }
            }
        },
        "minions": [
            {
                "config": {
                    "container__config__name": 'minion_{0}_{1}_{2}'.format(fake.word(), fake.word(), os.environ.get('ST_JOB_ID', '')),  # pylint: disable=no-member
                    "container__config__salt_config__id": minion_id
                }
            }
        ]
    }]} 
开发者ID:openSUSE,项目名称:salt-toaster,代码行数:23,代码来源:test_proxy.py

示例10: configure

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def configure():
    from faker import Faker
    fake = Faker()

    settings.configure(
        DATABASES={
            'default': {
                'ENGINE': 'django.db.backends.sqlite3',
                'NAME': ':memory:',
            }
        },
        INSTALLED_APPS=(
            'django_seed',
            'django_nose',
        ),
        TEST_RUNNER = 'django_nose.NoseTestSuiteRunner',
        NOSE_ARGS = [
            '--with-coverage',
            '--cover-package=django_seed',
        ],
        SITE_ID=1,
        SECRET_KEY=fake.sha1(),
    ) 
开发者ID:Brobin,项目名称:django-seed,代码行数:25,代码来源:runtests.py

示例11: __init__

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def __init__(self, tenant, provider, current_month_only=False, config=None):
        """Set up the class."""
        # prevent future whammy:
        assert isinstance(tenant, Tenant), "not a Tenant type"
        assert isinstance(provider, Provider), "not a Provider type"
        assert isinstance(current_month_only, bool), "not a bool type"
        if config:
            assert isinstance(config, FakeAzureConfig), "not a FakeAzureConfig type"

        self.tenant = tenant
        self.provider = provider
        self.current_month_only = current_month_only
        self.config = config if config else FakeAzureConfig()
        self.fake = Faker()
        self.dh = DateHelper()
        self.provider_uuid = provider.uuid
        self.ocp_generator = None

        # generate a list of dicts with unique keys.
        self.period_ranges, self.report_ranges = self.report_period_and_range() 
开发者ID:project-koku,项目名称:koku,代码行数:22,代码来源:helpers.py

示例12: fake_arn

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def fake_arn(account_id="", service="fakeservice", region="", resource_separator=":", generate_account_id=False):
    """
    Generate a dummy AWS ARN for testing purposes.

    account_id argument is optional, and will be randomly generated if None.
    Args:
        account_id (str): Optional account ID.
        service (str): Optional service name
        region (str): Optional region
        resource_separator (str): A colon ':' or a forward-slash '/'
        generate_account_id (bool): Whether to generate a random account_id,
                        This will override any account_id that is passed in
    Returns:
        str: A well-formed, randomized ARN.

    """
    if generate_account_id:
        account_id = fake_aws_account_id()
    resource = faker.Faker().name()
    resource_type = faker.Faker().name().replace(" ", "_")
    arn = ("arn:aws:{0}:{1}:{2}:{3}{4}{5}").format(
        service, region, account_id, resource_type, resource_separator, resource
    )
    return arn 
开发者ID:project-koku,项目名称:koku,代码行数:26,代码来源:__init__.py

示例13: test_logo_image

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def test_logo_image(self):
        homepage = HomePage.objects.get()
        self.assertIsNone(homepage.logo_image)
        with self.settings(CONFERENCE_ID=self.conference.id):
            # Test that default logo image appears.
            response = self.client.get(homepage.url)
            self.assertContains(response, "/logo.png")
            # Replace default logo with a new image.
            test_logo_name = Faker().uuid4()
            image_file = ImageFile(
                open("conf_site/cms/tests/test-logo.png", "rb"), test_logo_name
            )
            ImageModel = get_image_model()
            image = ImageModel(file=image_file)
            # The image must be saved before it is attached
            # to the homepage.
            image.save()
            homepage.logo_image = image
            homepage.save()
            response = self.client.get(homepage.url)
            self.assertNotContains(response, "/logo.288981a8dfa8.png")
            self.assertContains(response, test_logo_name) 
开发者ID:pydata,项目名称:conf_site,代码行数:24,代码来源:test_homepage_context.py

示例14: setUp

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def setUp(self):
        super().setUp()

        self.faker = Faker()

        USER_EMAIL = self.faker.email()
        USER_PASSWORD = self.faker.password()
        self.user = get_user_model().objects.create_user(
            username=self.faker.profile()["username"],
            email=USER_EMAIL,
            password=USER_PASSWORD,
        )
        speaker = Speaker.objects.create(name=self.faker.name())
        speaker.user = self.user
        speaker.save()

        # Overwrite speaker for this case's proposal.
        self.proposal.speaker = speaker
        self.proposal.save()

        self.assertTrue(
            self.client.login(username=USER_EMAIL, password=USER_PASSWORD)
        ) 
开发者ID:pydata,项目名称:conf_site,代码行数:25,代码来源:__init__.py

示例15: test_mass_html_mail

# 需要导入模块: import faker [as 别名]
# 或者: from faker import Faker [as 别名]
def test_mass_html_mail(self):
        test_data = list()
        faker = Faker()
        for i in range(random.randint(3, 7)):
            test_data.append((
                faker.sentence(),
                faker.word(), "<strong>{}</strong>".format(faker.word()),
                "test@ps", [],
            ))
            for j in range(random.randint(1, 3)):
                test_data[i][4].append(faker.email())

        result = send_mass_html_mail(test_data)
        self.assertEqual(result, len(test_data))
        self.assertEqual(len(mail.outbox), len(test_data))
        for i in range(len(test_data)):
            for j in range(len(test_data[i][4])):
                self.assertEqual(mail.outbox[i].subject, test_data[i][0])
                self.assertEqual(mail.outbox[i].from_email, settings.DEFAULT_FROM_EMAIL)
                self.assertEqual(mail.outbox[i].to, test_data[i][4]) 
开发者ID:tejoesperanto,项目名称:pasportaservo,代码行数:22,代码来源:test_utils.py


注:本文中的faker.Faker方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。