Generate Model Factory (factory_boy) for each model of your Django app
Project description
django-factory-generator
Generate (factory_boy) Model Factory for each model of your Django app
Changelog
1.0.0 Init project
Requirements
This Django app generates factory_boy Model Factories from your installed apps, so you need to have factory_boy installed.
Installation
Install using pip :
pip install django_factory_generator
Add factory_generator to your INSTALLED_APPS settings.
INSTALLED_APPS = (
...
'factory_generator',
...
)
Generate factories
Generate factories with a single command line:
python manage.py generate_factories
This will create a model_factories directory with the following structure :
|__ model_factories/ |__ app_label_foo/ |__ __init__.py |__ model_foo.py |__ model_bar.py |__ base/ |__ __init__.py |__ model_foo.py |__ model_bar.py
Each model results in two generated files :
model_factories/app_label_foo/base/model_foo containing the ModelFooFactoryBase class definition generated from the model ModelFoo. This file should not be manually edited since it would be overriden each time the command generate_factories is run.
model_factories/app_label_foo/model_foo containing the ModelFooFactory class which simply extends ModelFooFactoryBase. This file is generated once but not overriden when you run the generate_factories command again.
This structure gives you the ability to override the ModelFactory that was automatically generated. You can then edit the ModelFooFactory to change / edit the base fields that were generated.
You can then import your model factories the following way:
# app_label/tests.py from django.test import TestCase from model_factories.app_label import ModelFooFactory, ModelBarFactory class FooTests(TestCase): def test_model_factory(self): modelfoo = ModelFooFactory( foo='bar', ) modelbar = ModelBarFactory( bar='baz', ) # Run your tests here
Settings
Here are all the settings you can use, with their default value :
FACTORY_NORMALIZE_FIELD_MAP = {} FACTORY_FIELD_FAKER_MAP = {} FACTORY_IGNORE_FIELDS = [] FACTORY_ROOT_DIR = 'model_factories' FACTORY_IGNORE_NON_EDITABLE_FIELDS = True
Todo
Improve documentation
Write unit tests
validate compatibility with previous versions of Django and Python
Support
If you are having issues, please let us know or submit a pull request.
License
The project is licensed under the MIT License.
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
Built Distribution
File details
Details for the file django_factory_generator-1.0.0.tar.gz
.
File metadata
- Download URL: django_factory_generator-1.0.0.tar.gz
- Upload date:
- Size: 10.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebd9e64b155ba0071afb3f16f45635a1926ba3d5a5262cb17632cb6230c91656 |
|
MD5 | 962b7c9ae11b16db192903312d67968f |
|
BLAKE2b-256 | 985142bb2459b2ebd23e4845743ef605df1245b5d330cc7bd2248074d4ab5579 |
File details
Details for the file django_factory_generator-1.0.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_factory_generator-1.0.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28b8afc23d44d461b1cd6adeaac9831aac43271aceebdb63f2a66f471e9be075 |
|
MD5 | 22c96c663c0e3e54ee4742f1f84cad90 |
|
BLAKE2b-256 | e80c5e381f9fbcb713bf5ce7f8f6de0baa74d85f156b3b40653798e96b7b00de |