Skip to main content

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.

Test Status Latest PyPI version Documentation Status

Install

pip install model_bakery

Usage and Info

Basic usage

# models.py

class Customer(models.Model):
    happy = models.BooleanField()
    name = models.CharField(max_length=30)
    age = models.IntegerField()
    bio = models.TextField()
    wanted_games_qtd = 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),
 'happy': True,
 'id': 1,
 'last_shopping': datetime.datetime(2019, 12, 3, 21, 42, 34, 77019),
 'name': 'qiayYnESvqcYLLBzxpFOcGBIfnQEPx',
 'wanted_games_qtd': 6016}
"""

Check out documentation for more complete examples.

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

Uploaded Source

Built Distribution

model_bakery-1.1.0-py2.py3-none-any.whl (17.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: model_bakery-1.1.0.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for model_bakery-1.1.0.tar.gz
Algorithm Hash digest
SHA256 aea339f47aa3b044d1a6d62f54c04686285fa0397a05de29ec6809a2a6f9bdc5
MD5 deea65e461433d993d2151503957605f
BLAKE2b-256 dd68430708417b7923b25d47b6c7ea10396dfebcdb9dce2772938715f3fa7194

See more details on using hashes here.

File details

Details for the file model_bakery-1.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: model_bakery-1.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.8

File hashes

Hashes for model_bakery-1.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 44321cded0e130c31e3cdd7589f8c3d551e12e9ebcc8425aff800dfeaf91539a
MD5 bbedbf4c3908f095c11d75513bf6494c
BLAKE2b-256 7d6fe5a6b7ef51659b76f78490ade55d02343d590d56a481b56f14ad9f860cfc

See more details on using hashes here.

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