當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。