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.19.4.tar.gz
(20.9 kB
view details)
Built Distribution
File details
Details for the file model_bakery-1.19.4.tar.gz
.
File metadata
- Download URL: model_bakery-1.19.4.tar.gz
- Upload date:
- Size: 20.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c18882cbe29cff80c4dad238243f93174eaf02aef7f805f0d44606c57271d44 |
|
MD5 | 5aa859af18fbcbcbb6b80764ed8880ae |
|
BLAKE2b-256 | 61d594453f5fc22bb00179867cdca886d4a393b6c9db316c5d60a2e34af4f198 |
Provenance
File details
Details for the file model_bakery-1.19.4-py3-none-any.whl
.
File metadata
- Download URL: model_bakery-1.19.4-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9134a24a2cecc861460993c652dc62ab0a0cd73dd8c3581cd273a3b793fad078 |
|
MD5 | 297bf38e92cffae178c25a34b5c241dd |
|
BLAKE2b-256 | 8a40e7147f4ca31032fd97061da0bcc167cd7e82ae0bbc022680e9d5bf514628 |