本文整理汇总了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"))
示例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
示例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)
示例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',
示例5: get_faker
def get_faker():
faker = Factory()
return faker.create()
示例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
示例7: Faker
def Faker(*args,**kwargs):
return Factory.create(*args,**kwargs)
示例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)
示例9: _get_name
def _get_name():
factory = Factory()
faker = factory.create()
return faker.name()
示例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)