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.

Note: Model Bakery is a rename of the legacy Model Mommy project.

Installation

pip install model-bakery

Basic usage

# models.py
from django.db import models

class Customer(models.Model):
    name = models.CharField(max_length=30)
    email = models.EmailField()
    age = models.IntegerField()
    is_jards_macale_fan = models.BooleanField()
    bio = models.TextField()
    birthday = models.DateField()
    last_shopping = models.DateTimeField()

# test_models.py
from django.test import TestCase
from model_bakery import baker

class TestCustomerModel(TestCase):
    def setUp(self):
        self.customer = baker.make('shop.Customer')
        print(self.customer.__dict__)

"""
{'_state': <django.db.models.base.ModelState object at 0x1129a3240>,
 'age': 3841,
 'bio': 'vUFzMUMyKzlnTyiCxfgODIhrnkjzgQwHtzIbtnVDKflqevczfnaOACkDNqvCHwvtWdLwoiKrCqfppAlogSLECtMmfleeveyqefkGyTGnpbkVQTtviQVDESpXascHAluGHYEotSypSiHvHzFteKIcUebrzUVigiOacfnGdvijEPrZdSCIIBjuXZMaWLrMXyrsUCdKPLRBRYklRdtZhgtxuASXdhNGhDsrnPHrYRClhrSJSVFojMkUHBvSZhoXoCrTfHsAjenCEHvcLeCecsXwXgWJcnJPSFdOmOpiHRnhSgRF',
 'birthday': datetime.date(2019, 12, 3),
 'email': 'rpNATNsxoj@example.com',
 'is_jards_macale_fan': True,
 'id': 1,
 'last_shopping': datetime.datetime(2019, 12, 3, 21, 42, 34, 77019),
 'name': 'qiayYnESvqcYLLBzxpFOcGBIfnQEPx'}
"""

Documentation

For more detailed information, check out the full documentation.

Contributing

As an open-source project, Model Bakery welcomes contributions of many forms:

  • Code patches
  • Documentation improvements
  • Bug reports

Take a look at our contribution guidelines for instructions on how to set up your local environment.

Maintainers

Creator

License

Model Bakery is licensed under the MIT License. See the LICENSE file for more information.

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

Uploaded Source

Built Distribution

model_bakery-1.20.5-py3-none-any.whl (24.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: model_bakery-1.20.5.tar.gz
  • Upload date:
  • Size: 21.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for model_bakery-1.20.5.tar.gz
Algorithm Hash digest
SHA256 107b3efb8889baac83cae0e2d81465903b69a70eeb99ecfd0929d959a653ab90
MD5 1d32be7132eb0daeb59d938bd1039940
BLAKE2b-256 bf7324854c5053c852201b4799e7837060496d1418a28488a90a299e8d9c618b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: model_bakery-1.20.5-py3-none-any.whl
  • Upload date:
  • Size: 24.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for model_bakery-1.20.5-py3-none-any.whl
Algorithm Hash digest
SHA256 796e0b7fa6bf2acc09feaadce40c6bcc13e5b55c5bdff9f76e87ceb64f736070
MD5 4a745622c581b18d04fd391e5f03ea26
BLAKE2b-256 134b157c1113e317f79a257b4dfe0607dbab7f57bec67a34d053588dfb8945ac

See more details on using hashes here.

Supported by

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