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.17.0.tar.gz
(20.6 kB
view details)
Built Distribution
File details
Details for the file model_bakery-1.17.0.tar.gz
.
File metadata
- Download URL: model_bakery-1.17.0.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe808132cd966164600f0450cc05b3cfa50c6c062e00f739a861c5a4b9f236ca |
|
MD5 | 1024f4a69d6670562f03c1660dfc8d91 |
|
BLAKE2b-256 | fc5b646517242f448195fe4eba055e5a72bc5a6de180bc0ba172503df8c7c5f9 |
File details
Details for the file model_bakery-1.17.0-py3-none-any.whl
.
File metadata
- Download URL: model_bakery-1.17.0-py3-none-any.whl
- Upload date:
- Size: 23.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d26f1a7043c46e6729145b964a7740bf8f6dddac16510fd18323a1492fba757 |
|
MD5 | 15173f6a4b492dd6e82b28cf9991c955 |
|
BLAKE2b-256 | c1385f397a730621b120c5dbe0c2afb7912896a627ec703d972a1de3e3484434 |