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


Python factory.Factory类代码示例

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


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

示例1: test_http_put

 def test_http_put(self):
     fake = Factory.create("en_GB")
     client = AsyncHTTPClient(self.io_loop)
     for _ in range(10):
         data = {"item":{
             "email":     fake.email(),
             "firstname": fake.first_name(),
             "lastname":  fake.last_name(),
             "_password": fake.password()
         }}
         client.fetch("{}Person".format(BASE_URL), self.stop, 
                      method="PUT", 
                      body=dumps(data),
                      headers={"Content-Type": "application/json",
                               "simple-auth-token":"--foo-bar--"})
         response = self.wait()
         result = loads(response.body.decode("utf-8"))
         if result.get("error"):
             raise Exception(result["error"])
         
     for _ in range(10):
         data = {"item":{
             "name":  fake.name(),
             "dob": fake.date(),
             "active": fake.pybool(),
             "customer_type": "retail"
         }}
         client.fetch("{}Customer".format(BASE_URL), self.stop, 
                      method="PUT", 
                      body=dumps(data),
                      headers={"Content-Type": "application/json",
                               "simple-auth-token":"--foo-bar--"})
         response = self.wait()
         result = loads(response.body.decode("utf-8"))
         if result.get("error"):
             raise Exception(result["error"])
         
         data = {
             "item": {
                 "line1":  fake.address(),
                 "town": fake.city(),
                 "postcode": fake.postcode(),
                 "customer_type": "retail"
             },
             "to_add": [
                        [
                         "customers",
                         "Customer",
                         result["result"]["id"]
                        ]
                     ]
         }
         client.fetch("{}Address".format(BASE_URL), self.stop, 
                      method="PUT", 
                      body=dumps(data),
                      headers={"Content-Type": "application/json",
                               "simple-auth-token":"--foo-bar--"})
         response = self.wait()
         result = loads(response.body.decode("utf-8"))
开发者ID:blueshed,项目名称:blueshed-py,代码行数:59,代码来源:test_rest_service.py

示例2: AccountFactory

import factory
from factory.declarations import LazyAttribute
from factory.django import DjangoModelFactory
from faker.factory import Factory

from lily.tenant.factories import TenantFactory
from lily.utils.models.factories import PhoneNumberFactory

from .models import Account

faker = Factory.create()


class AccountFactory(DjangoModelFactory):
    tenant = factory.SubFactory(TenantFactory)
    name = LazyAttribute(lambda o: faker.company())
    description = LazyAttribute(lambda o: faker.bs())

    @factory.post_generation
    def phone_numbers(self, create, extracted, **kwargs):
        phone_str = faker.phone_number()
        if create:
            phone_number = PhoneNumberFactory(tenant=self.tenant, raw_input=phone_str)
            self.phone_numbers.add(phone_number)

    class Meta:
        model = Account
开发者ID:noordzij,项目名称:hellolily,代码行数:27,代码来源:factories.py

示例3: createTickets

            # TODO: Add logging

def createTickets():
    with open('tickets_list.csv', 'wb') as csvfile:
        write_to_csv = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
        write_to_csv.writerow(['ticket_id,', 'ticket_date,', 'ticket_desc'])
        for _ in range(1000):
            ticket_id = fake.random_int(min=100, max=99999)
            ticket_date = fake.date_time_between(start_date="-100d", end_date="now")
            ticket_desc = "Customer site returning a 500 instead of site content. Site has been down for 15 minutes."
            write_to_csv.writerow((ticket_id, ticket_date, ticket_desc))
        # Add spikes in tickets every 10 days
        # TODO: Add logging

def createZabbix():
    with open('zabbix_list.csv', 'wb') as csvfile:
        write_to_csv = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
        write_to_csv.writerow(['zabbix_id,', 'zabbix_date,', 'zabbix_desc'])
        for _ in range(1000):
            zabbix_id = fake.random_int(min=100, max=99999)
            zabbix_date = fake.date_time_between(start_date="-100d", end_date="now")
            server_number = random.randint(1000,99999)
            zabbix_desc = "Server number {} is down.".format(server_number)
            write_to_csv.writerow((zabbix_id, zabbix_date, zabbix_desc))
        # Add spikes in tickets every 10 days
        # TODO: Add logging

if __name__ == "__main__":
    fake = Factory.create('en_US')
    writeTo_csv(fake)
开发者ID:caldwelljs,项目名称:velocity-prep,代码行数:30,代码来源:fake-deploy-data.py

示例4: import

import factory

from factory.declarations import (SubFactory, LazyAttribute, SelfAttribute,
                                  Sequence, Iterator)
from factory.django import DjangoModelFactory
from factory.fuzzy import FuzzyChoice, FuzzyDate
from faker.factory import Factory

from lily.accounts.factories import AccountFactory
from lily.tenant.factories import TenantFactory
from lily.users.factories import LilyUserFactory
from lily.users.models import Team

from .models import Case, CaseStatus, CaseType

faker = Factory.create('nl_NL')

CASESTATUS_CHOICES = (
    'New',
    'Closed',
    'Pending input',
    'Waiting on hardware',
    'Follow up',
    'Client will contact us',
    'Documentation',
)

CASETYPE_CHOICES = (
    'Config',
    'Support',
    'Return Shipment',
开发者ID:HelloLily,项目名称:hellolily,代码行数:31,代码来源:factories.py

示例5: get_faker

def get_faker():
    faker = Factory()
    return faker.create()
开发者ID:c0debrain,项目名称:flask-cms,代码行数:3,代码来源:make_models.py

示例6: AccountFactory

import factory
from factory.declarations import LazyAttribute
from factory.django import DjangoModelFactory
from faker.factory import Factory

from lily.tenant.factories import TenantFactory
from lily.utils.models.factories import PhoneNumberFactory

from .models import Account

faker = Factory.create("nl_NL")


class AccountFactory(DjangoModelFactory):
    tenant = factory.SubFactory(TenantFactory)
    name = LazyAttribute(lambda o: faker.company())
    description = LazyAttribute(lambda o: faker.bs())

    @factory.post_generation
    def phone_numbers(self, create, extracted, **kwargs):
        phone_str = faker.phone_number()
        if create:
            phone_number = PhoneNumberFactory(tenant=self.tenant, raw_input=phone_str)
            self.phone_numbers.add(phone_number)

    class Meta:
        model = Account
开发者ID:Vegulla,项目名称:hellolily,代码行数:27,代码来源:factories.py

示例7: Faker

def Faker(*args,**kwargs):
    return Factory.create(*args,**kwargs)
开发者ID:PeteRichardson,项目名称:faker,代码行数:2,代码来源:__init__.py

示例8: CleanModelFactory

from typing import Generator

from django.contrib.auth import get_user_model
from django.core.exceptions import ValidationError
from factory import LazyFunction, PostGenerationMethodCall, lazy_attribute, post_generation
from factory.django import DjangoModelFactory
from faker.factory import Factory as FakerFactory

faker = FakerFactory.create(providers=[])
max_retries = 200


class CleanModelFactory(DjangoModelFactory):
    """
    Ensures that created instances pass Django's `full_clean` checks.
    """
    class Meta:
        abstract = True

    @classmethod
    def _create(cls, model_class, *args, **kwargs):
        """
        Call `full_clean` on any created instance before saving

        Returns:
            model_class

        Raises:
            RuntimeError: Raised when validation fails on built model instance.
        """
        obj = model_class(*args, **kwargs)
开发者ID:jamescooke,项目名称:factory_djoy,代码行数:31,代码来源:factories.py

示例9: _get_name

def _get_name():
    factory = Factory()
    faker = factory.create()
    return faker.name()
开发者ID:erhuabushuo,项目名称:flask-cms,代码行数:4,代码来源:context_processors.py

示例10: createTickets

def createTickets():
    with open("tickets.csv", "wb") as csvfile:
        write_to_csv = csv.writer(csvfile, delimiter=",", quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
        write_to_csv.writerow(["ticket_id", "ticket_date", "ticket_desc"])
        for _ in range(1000):
            ticket_id = fake.random_int(min=100, max=99999)
            ticket_date = fake.date_time_between(start_date="-100d", end_date="now")
            ticket_desc = "Customer site returning a 500 instead of site content. Site has been down for 15 minutes."
            write_to_csv.writerow((ticket_id, ticket_date, ticket_desc))
        # Add spikes in tickets every 10 days
        # TODO: Add logging


def createZabbix():
    with open("zabbix.csv", "wb") as csvfile:
        write_to_csv = csv.writer(csvfile, delimiter=",", quotechar='"', quoting=csv.QUOTE_NONNUMERIC)
        write_to_csv.writerow(["zabbix_id", "zabbix_date", "zabbix_desc"])
        for _ in range(1000):
            zabbix_id = fake.random_int(min=100, max=99999)
            zabbix_date = fake.date_time_between(start_date="-100d", end_date="now")
            server_number = random.randint(1000, 99999)
            zabbix_desc = "Server number {} is down.".format(server_number)
            write_to_csv.writerow((zabbix_id, zabbix_date, zabbix_desc))
        # Add spikes in tickets every 10 days
        # TODO: Add logging


if __name__ == "__main__":
    fake = Factory.create("en_US")
    writeTo_csv(fake)
开发者ID:nprogers-WPE,项目名称:velocity-prep,代码行数:30,代码来源:fake-deploy-data.py


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