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
from django.db import models
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.20.0.tar.gz
(21.0 kB
view details)
Built Distribution
File details
Details for the file model_bakery-1.20.0.tar.gz
.
File metadata
- Download URL: model_bakery-1.20.0.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec9dc846b9a00b20f92df38fac310263323ab61b59b6eeebf77a4aefb0412724 |
|
MD5 | 3a33d6130369391c7c335950d86e2f07 |
|
BLAKE2b-256 | 312d9f61b529c788b367a6bac5b211bf8879036b4bcb27a5e9e78808131ea6fb |
Provenance
File details
Details for the file model_bakery-1.20.0-py3-none-any.whl
.
File metadata
- Download URL: model_bakery-1.20.0-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 875326466f5982ee8f0281abdfa774d78893d5473562575dfd5a9304ac7c5b8c |
|
MD5 | b9f6ca5b3fada12907f6257e8e3f6d8d |
|
BLAKE2b-256 | 60f0c6a6c8ac6fd1dd3c0241ac69230af6592e573d3dedc2ff95b22a352c10f2 |