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


Python Factory.create方法代码示例

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


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

示例1: __init__

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def __init__(self, locale=None, seed=None):
        '''Base class for DB handlers
        '''

        # Validating locale specified by user:
        # If specified locale not in faker.config.AVAILABLE_LOCALES
        # then faker.Factory will initialized with default locale ('en_US')
        if not locale:
            self.faker = Factory.create()
        else:
            try:
                self.faker = Factory.create(locale)
            except Exception:
                logger.warning("Specified locale is wrong or unsupported: '%s'; 'en_US' will be used!" % locale, extra=d)
                self.faker = Factory.create()

        # Setting the seed value for the random generator
        if seed is not None:
            self.faker.seed(seed) 
开发者ID:emirozer,项目名称:fake2db,代码行数:21,代码来源:base_handler.py

示例2: make_mock_transfer_sub

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def make_mock_transfer_sub(from_org, to_org):
    sub = factories.FormSubmissionWithOrgsFactory.create(
        organizations=[from_org])
    application = sub.applications.first()
    author = from_org.profiles.first().user
    # make a status_update prior to transfer
    factories.StatusUpdateWithNotificationFactory.create(
        application=application, author=author)
    transfer, *stuff = services.transfers_service.transfer_application(
        author=author, application=application,
        to_organization=to_org, reason="Transporter malfunction")
    message = 'Your case has been transferred to {}.\n{}'.format(
        to_org.name, to_org.short_confirmation_message)
    factories.StatusNotificationFactory.create(
        status_update=transfer.status_update, base_message=message,
        sent_message=message)
    return sub 
开发者ID:codeforamerica,项目名称:intake,代码行数:19,代码来源:mock.py

示例3: create_admin

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def create_admin():
    user = User.create(
        username="admin", email="admin@163.com", password="admin", is_active=True
    )
    create_fake_address(user.id)
    create_fake_address(user.id)
    create_fake_address(user.id)
    UserRole.create(user_id=user.id, role_id=4)
    yield f"Admin {user.username} created"
    user = User.create(username="op", email="op@163.com", password="op", is_active=True)
    UserRole.create(user_id=user.id, role_id=3)
    yield f"Admin {user.username} created"
    user = User.create(
        username="editor", email="editor@163.com", password="editor", is_active=True
    )
    UserRole.create(user_id=user.id, role_id=2)
    yield f"Admin {user.username} created" 
开发者ID:hjlarry,项目名称:flask-shop,代码行数:19,代码来源:random_data.py

示例4: create_order_line

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def create_order_line(order, discounts):
    product = Product.query.order_by(func.random()).first()
    variant = product.variant[0]
    quantity = random.randrange(1, 5)
    variant.quantity += quantity
    variant.save()
    return OrderLine.create(
        order_id=order.id,
        product_name=variant.display_product(),
        product_sku=variant.sku,
        product_id=variant.sku.split("-")[0],
        is_shipping_required=variant.is_shipping_required,
        quantity=quantity,
        variant_id=variant.id,
        unit_price_net=variant.price,
    )


# step27 
开发者ID:hjlarry,项目名称:flask-shop,代码行数:21,代码来源:random_data.py

示例5: test_create_order_error_cannot_retrieve_service_worker

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def test_create_order_error_cannot_retrieve_service_worker(self, utils_mock):
        discount = 100.0
        sales_force_id = 'other-sales_force_id'
        utils_mock.return_value = None
        enterprise_customer_user = factories.EnterpriseCustomerUserFactory()
        course_run_id = 'course-v1:edX+DemoX+Demo_Course'

        expected_messages = [
            self.order_create_log_message.format(
                enterprise_customer_user.user_id,
                course_run_id,
                discount,
                sales_force_id
            ),
            'Could not create order for enterprise learner with id [{}] for enrollment in course with id [{}]. Reason: '
            '[{}]'.format(
                enterprise_customer_user.user_id,
                course_run_id,
                'Failed to retrieve a valid ecommerce worker.')
        ]

        with LogCapture(level=logging.DEBUG) as log_capture:
            enterprise_customer_user.create_order_for_enrollment(course_run_id, discount, sales_force_id)
            for index, message in enumerate(expected_messages):
                assert message in log_capture.records[index].getMessage() 
开发者ID:edx,项目名称:edx-enterprise,代码行数:27,代码来源:test_models.py

示例6: test_create_order_error_cannot_create_ecommerce_api_client

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def test_create_order_error_cannot_create_ecommerce_api_client(self, utils_mock):
        discount = 0.0
        sales_force_id = 'another-sales_force_id'
        user = factories.UserFactory()
        utils_mock.return_value = user
        enterprise_customer_user = factories.EnterpriseCustomerUserFactory()
        course_run_id = 'course-v1:edX+DemoX+Demo_Course'

        expected_messages = [
            self.order_create_log_message.format(
                enterprise_customer_user.user_id,
                course_run_id,
                discount,
                sales_force_id
            ),
            'edx-enterprise unexpectedly failed as if not installed in an OpenEdX platform',
            'Could not create order for enterprise learner with id [{}] for enrollment in course with id [{}]'.format(
                enterprise_customer_user.user_id,
                course_run_id),
        ]

        with LogCapture(level=logging.DEBUG) as log_capture:
            enterprise_customer_user.create_order_for_enrollment(course_run_id, discount, sales_force_id)
            for index, message in enumerate(expected_messages):
                assert message in log_capture.records[index].getMessage() 
开发者ID:edx,项目名称:edx-enterprise,代码行数:27,代码来源:test_models.py

示例7: setUp

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def setUp(self):
        self.user = UserFactory.create(is_staff=True, is_active=True)
        self.user.set_password("QWERTY")
        self.user.save()
        self.client = Client()
        self.demo_course_id = 'course-v1:edX+DemoX+Demo_Course'
        self.dummy_demo_course_modes = [
            {
                "slug": "professional",
                "name": "Professional Track",
                "min_price": 100,
                "sku": "sku-audit",
            },
            {
                "slug": "audit",
                "name": "Audit Track",
                "min_price": 0,
                "sku": "sku-audit",
            },
        ]
        super(TestHandleConsentEnrollmentView, self).setUp() 
开发者ID:edx,项目名称:edx-enterprise,代码行数:23,代码来源:test_handle_consent_enrollment.py

示例8: setUp

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def setUp(self):
        """
        Set up reusable fake data.
        """
        self.user = UserFactory.create(is_staff=True, is_active=True)
        self.user.set_password("QWERTY")
        self.user.save()
        self.client = Client()
        self.demo_course_1 = FAKE_PROGRAM_RESPONSE3['courses'][0]
        self.demo_course_2 = FAKE_PROGRAM_RESPONSE3['courses'][1]
        self.demo_course_id1 = FAKE_PROGRAM_RESPONSE3['courses'][0]['key']
        self.demo_course_id2 = FAKE_PROGRAM_RESPONSE3['courses'][1]['key']
        self.demo_course_ids = [self.demo_course_id1, self.demo_course_id2]
        self.dummy_program_uuid = FAKE_PROGRAM_RESPONSE3['uuid']
        self.dummy_program = FAKE_PROGRAM_RESPONSE3
        super(TestProgramEnrollmentView, self).setUp() 
开发者ID:edx,项目名称:edx-enterprise,代码行数:18,代码来源:test_program_enrollment_view.py

示例9: init_api_test_data

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def init_api_test_data():
    """
    Generates fake data, starts an HttpClient session, creates a fake user and
    logs that user in.
    """
    call_command("migrate", verbosity=0)
    call_command("fake", verbosity=0, iterations=1)

    c = HttpClient()

    fake_user = fake.simple_profile()
    fake_password = fake.password()
    user = User.objects.create_user(
        fake_user["username"], fake_user["mail"], fake_password
    )
    site_permission = SitePermission.objects.create(user=user)
    site_permission.sites.set(Site.objects.filter(id=1))
    site_permission.save()

    user = User.objects.get(username=fake_user["username"])
    c.login(username=fake_user["username"], password=fake_password)

    return [c, user] 
开发者ID:overshard,项目名称:timestrap,代码行数:25,代码来源:tests.py

示例10: setUp

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def setUp(self):
        call_command("migrate", verbosity=0)
        self.user = User.objects.first()
        client = Client.objects.create(name="Timestrap")
        self.project = Project.objects.create(client=client, name="Testing")

        Entry.objects.create(
            project=self.project,
            user=self.user,
            duration=timedelta(hours=1),
            note="Creating tests for the core app",
        )
        Entry.objects.create(
            project=self.project,
            user=self.user,
            duration=timedelta(hours=2),
            note="Continue creating tests for the core app",
        ) 
开发者ID:overshard,项目名称:timestrap,代码行数:20,代码来源:tests.py

示例11: init

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def init(loop):
    print("Generating Fake Data")
    pg = await init_postgres(conf['postgres'], loop)
    fake = Factory.create()
    fake.seed(1234)
    await prepare_tables(pg)

    rows = 1000

    tag_ids = await generate_tags(pg, 500, fake)
    post_ids = await generate_posts(pg, rows, fake, tag_ids)
    await generate_comments(pg, 25, fake, post_ids) 
开发者ID:aio-libs,项目名称:aiohttp_admin,代码行数:14,代码来源:generate_data.py

示例12: init

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def init(loop):
    print("Generating Fake Data")
    pg = await init_postgres(conf['postgres'], loop)
    fake = Factory.create()
    fake.seed(1234)
    await preapre_tables(pg)

    quiestion_num = 1000
    choices_num = 5
    question_ids = await generate_questions(pg, quiestion_num, fake)
    await generate_choices(pg, choices_num, fake, question_ids)

    pg.close()
    await pg.wait_closed() 
开发者ID:aio-libs,项目名称:aiohttp_admin,代码行数:16,代码来源:generate_data.py

示例13: init

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def init(loop):
    print("Generating Fake Data")
    mongo = await init_mongo(conf['mongo'], loop)
    fake = Factory.create()
    fake.seed(1234)

    await prepare_coolections(mongo.user, mongo.message, mongo.follower)

    users = await generate_users(mongo.user, db.user, 100, fake)
    await generate_messages(mongo.message, db.message, 50, fake, users)
    user_ids = [v['_id'] for v in users]
    await generate_followers(mongo.follower, db.follower, 5, fake, user_ids) 
开发者ID:aio-libs,项目名称:aiohttp_admin,代码行数:14,代码来源:generate_data.py

示例14: authors

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def authors(self, create, extracted, **kwargs):
        if extracted:
            if isinstance(extracted, (list, tuple)):
                for author in extracted:
                    self.authors.add(author)
            else:
                self.authors.add(extracted) 
开发者ID:django-json-api,项目名称:django-rest-framework-json-api,代码行数:9,代码来源:factories.py

示例15: future_projects

# 需要导入模块: from faker import Factory [as 别名]
# 或者: from faker.Factory import create [as 别名]
def future_projects(self, create, extracted, **kwargs):
        if not create:  # pragma: no cover
            return
        if extracted:
            for project in extracted:
                self.future_projects.add(project) 
开发者ID:django-json-api,项目名称:django-rest-framework-json-api,代码行数:8,代码来源:factories.py


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