Smart object creation facility for Django.
Project description
Model Bakery: Smart fixtures for better tests
Model Bakery offers you a smart way to create fixtures for testing in Django. With a simple and powerful API you can create many objects with a single line of code.
Model Bakery is a rename of the legacy Model Mommy project.
Install
pip install model_bakery
Usage and Info
Basic usage
# models.py
class Customer(models.Model):
enjoy_jards_macale = models.BooleanField()
name = models.CharField(max_length=30)
email = models.EmailField()
age = models.IntegerField()
bio = models.TextField()
days_since_last_login = models.BigIntegerField()
birthday = models.DateField()
last_shopping = models.DateTimeField()
# test_models.py
from django.test import TestCase
from model_bakery import baker
from pprint import pprint
class TestCustomerModel(TestCase):
def setUp(self):
self.customer = baker.make('shop.Customer')
pprint(self.customer.__dict__)
"""
{'_state': <django.db.models.base.ModelState object at 0x1129a3240>,
'age': 3841,
'bio': 'vUFzMUMyKzlnTyiCxfgODIhrnkjzgQwHtzIbtnVDKflqevczfnaOACkDNqvCHwvtWdLwoiKrCqfppAlogSLECtMmfleeveyqefkGyTGnpbkVQTtviQVDESpXascHAluGHYEotSypSiHvHzFteKIcUebrzUVigiOacfnGdvijEPrZdSCIIBjuXZMaWLrMXyrsUCdKPLRBRYklRdtZhgtxuASXdhNGhDsrnPHrYRClhrSJSVFojMkUHBvSZhoXoCrTfHsAjenCEHvcLeCecsXwXgWJcnJPSFdOmOpiHRnhSgRF',
'birthday': datetime.date(2019, 12, 3),
'enjoy_jards_macale': True,
'id': 1,
'last_shopping': datetime.datetime(2019, 12, 3, 21, 42, 34, 77019),
'name': 'qiayYnESvqcYLLBzxpFOcGBIfnQEPx',
'days_since_last_login': 6016}
"""
Check out documentation for more complete examples.
Contributing
Detailed info here.
Maintainers
Creator
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
model_bakery-1.2.1.tar.gz
(50.7 kB
view hashes)
Built Distribution
Close
Hashes for model_bakery-1.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3260bd055c25998b54eda2082a507ba7fd113fe071156bdad065da426b14851 |
|
MD5 | ce54b0a219c3945622351ae90e4330e6 |
|
BLAKE2b-256 | d7a625b1e5042aec84c02b3e5cfdca05d3676c243df4a77147c3320f6e9ed875 |