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