Skip to main content

django-factory-generator v1.0.4 on PyPi MIT license Stable

django-factory-generator

Generate (factory_boy) Model Factory for each model of your Django app

Changelog

  • 1.0.4 fix has_choices property for Django 3.0

  • 1.0.3 Remove useless print statements

  • 1.0.2 Add PointFieldFaker to support PointField. Refactor the way modules are imported on generated factories

  • 1.0.1 Add more accurate fakers for BigIntegerField, IntegerField, PositiveIntegerField, PositiveSmallIntegerField and SmallIntegerField

  • 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.

Metadata

Release files for django-factory-generator 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-factory-generator 1.0.4
File Size Uploaded Provenance Actions
django_factory_generator-1.0.4.tar.gz 9.6 kB Without provenance Details for django_factory_generator-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-factory-generator 1.0.4
File Interpreter ABI Platform Actions
django_factory_generator-1.0.4-py2.py3-none-any.whl Python 3, Python 2 none any Details for django_factory_generator-1.0.4-py2.py3-none-any.whl

Total release size: 24.1 kB

Release files / django_factory_generator-1.0.4.tar.gz

Download URL django_factory_generator-1.0.4.tar.gz
Size 9.6 kB
Tags Source
SHA-256 checksum
How to use checksums
358c82b47828e7f700145f610e978eaa0ca346ed6c7c83befe26d26a3f1fb4d6
BLAKE2b-256 checksum
How to use checksums
e85deaf21773cab47d793fdef886d89ccae29ba43b3e0416db0ffea7d888c0f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.17

Release files / django_factory_generator-1.0.4-py2.py3-none-any.whl

Download URL django_factory_generator-1.0.4-py2.py3-none-any.whl
Size 14.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
23d64bd1ef65b0fa2e5120c016e222185939eac203dcda2370cc9e2dfce4632d
BLAKE2b-256 checksum
How to use checksums
edc8811e68c1b0d956d9634ce374c60a8aba5d47bb10df22cf93f8d0fd2cdace
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/41.4.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/2.7.17

Security for django-factory-generator 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page