Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/model-bakers/model_bakery
Object factory for Django
https://github.com/model-bakers/model_bakery
django fixtures object-factory python
Last synced: 28 days ago
JSON representation
Object factory for Django
- Host: GitHub
- URL: https://github.com/model-bakers/model_bakery
- Owner: model-bakers
- License: other
- Created: 2019-10-08T12:49:08.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-05-13T16:33:12.000Z (6 months ago)
- Last Synced: 2024-05-23T10:06:07.441Z (6 months ago)
- Topics: django, fixtures, object-factory, python
- Language: Python
- Homepage: https://model-bakery.readthedocs.io/en/latest/
- Size: 491 KB
- Stars: 803
- Watchers: 11
- Forks: 80
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- -awesome-django - model-bakery - Object factory for Django (rename of legacy Model Mommy project). (Third-Party Packages / Testing)
- awesome-django - model-bakery - Object factory for Django (rename of legacy Model Mommy project). (Third-Party Packages / Testing)
- awesome-python-testing - Model Bakery - offers you a smart way to create fixtures for testing in Django. (Object Factories)
- best-of-web-python - GitHub - 22% open · ⏱️ 03.06.2024): (Web Testing)
README
# Model Bakery: Smart fixtures for better tests
[![Build](https://img.shields.io/github/actions/workflow/status/model-bakers/model_bakery/ci.yml?branch=main)](https://github.com/model-bakers/model_bakery/actions?workflow=Tests)
[![Coverage](https://img.shields.io/badge/Coverage-97%25-success)](https://github.com/model-bakers/model_bakery/actions?workflow=Tests)
[![Latest PyPI version](https://img.shields.io/pypi/v/model_bakery.svg)](https://pypi.python.org/pypi/model_bakery/)
[![Documentation Status](https://readthedocs.org/projects/model-bakery/badge/?version=latest)](https://model-bakery.readthedocs.io/en/latest/?badge=latest)*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](https://pypi.org/project/model_mommy/).
## Install
```bash
pip install model-bakery
```## Usage and Info
### Basic usage
```python
# 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 pprintclass TestCustomerModel(TestCase):
def setUp(self):
self.customer = baker.make('shop.Customer')
pprint(self.customer.__dict__)"""
{'_state': ,
'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](https://github.com/model-bakers/model_bakery/blob/main/CONTRIBUTING.md).
## Maintainers
- [Bernardo Fontes](https://github.com/berinhard/)
- [Rustem Saiargaliev](https://github.com/amureki/)
- [Tim Klein](https://github.com/timjklein36)## Creator
- [Vanderson Mota](https://github.com/vandersonmota/)