Skip to main content

Smart object creation facility for Django.

Project description

Model Bakery: Smart fixtures for better tests

Build Coverage Latest PyPI version Documentation Status

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


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.18.1.tar.gz (20.4 kB view details)

Uploaded Source

Built Distribution

model_bakery-1.18.1-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file model_bakery-1.18.1.tar.gz.

File metadata

  • Download URL: model_bakery-1.18.1.tar.gz
  • Upload date:
  • Size: 20.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for model_bakery-1.18.1.tar.gz
Algorithm Hash digest
SHA256 8cc2b7b0879a2fc400808225a4c1f830b322b181007577b588f4d4aac5d4cb4b
MD5 6ce46c7dc3d03c95328020d499c2ee0c
BLAKE2b-256 f0493d4518492449de39d5e598ffe5e20feebb0c77ec848c0af3576603560fae

See more details on using hashes here.

Provenance

File details

Details for the file model_bakery-1.18.1-py3-none-any.whl.

File metadata

File hashes

Hashes for model_bakery-1.18.1-py3-none-any.whl
Algorithm Hash digest
SHA256 49d672d41e8c377854d42e50df61ff5ee56b91a3b2ff24372344c05c29166eb2
MD5 b3fec21d5b36a2d5f7b59d2307eea107
BLAKE2b-256 936d8a2e55dd411e6286b7affde5c5ea57325f37ccd3482e00dcea285d590e80

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page