Mimesis integration with factory_boy
.
➜ pip install mimesis_factory
Just look at the example below and you’ll understand how it works:
import datetime
import random
class Account(object):
def __init__(self, username, email, name, surname, age):
self.username = username
self.email = email
self.name = name
self.surname = surname
self.age = age
self.password = ''.join(str(random.randint(0, 10)) for _ in range(10))
self.date_joined = datetime.datetime.today()
def __str__(self):
return '{} ({})'.format(self.username, self.email)
Simply use the Mimesis
class from mimesis_factory
:
import factory
from mimesis_factory import Mimesis
from account import Account
class AccountFactory(factory.Factory):
class Meta:
model = Account
username = Mimesis('username', template='l_d')
name = Mimesis('name', gender='female')
surname = Mimesis('surname', gender='female')
age = Mimesis('age', minimum=18, maximum=28)
email = factory.LazyAttribute(
lambda o: '%[email protected]' % o.username
)
access_token = Mimesis('token', entropy=32)
mimesis_factory is released under the MIT License.