Skip to main content

Django Dynamic Fixture

Docs Status PyPI version PyPI - Python Version PyPI - Downloads

Latest version: 4.0.1 (Sep 2023)

Django Dynamic Fixture (DDF) is a complete and simple library to create dynamic model instances for testing purposes.

It lets you focus on your tests, instead of focusing on generating some dummy data which is boring and polutes the test source code.

Basic Examples

Customize only the important details of the test:

    from ddf import G
    from my_library import Author, Book

    def test_search_book_by_author():
        author1 = G(Author)
        author2 = G(Author)
        book1 = G(Book, authors=[author1])
        book2 = G(Book, authors=[author2])
        books = Book.objects.search_by_author(author1.name)
        assert book1 in books
        assert book2 not in books

Using some goodies to keep the test code smaller:

    from ddf import G

    def test_search_book_by_author():
        author1, author2 = G('my_library.Author', n=2)
        book1 = G('my_library.Book', authors=[author1])
        book2 = G('my_library.Book', authors=[author2])
        books = Book.objects.search_by_author(author1.name)
        assert book1 in books
        assert book2 not in books

Configuring data from relationship fields:

    from ddf import G

    def test_search_book_by_author():
        book1 = G(Book, main_author__name='Eistein')
        book2 = G(Book)
        books = Book.objects.search_by_author(book1.main_author.name)
        assert book1 in books
        assert book2 not in books
        assert book1.main_author.name == 'Eistein'

Cheat Sheet

# Import the main DDF features
from ddf import N, G, F, M, C, P, teach # meaning: New, Get, ForeignKey, Mask, Copier, Print, teach
# `N` creates an instance of model without saving it to DB
instance = N(Book)
# `G` creates an instance of model and save it into the DB
instance = G(Book)
# `F` customize relationship objects
instance = G(Book, author=F(name='Eistein'))
# Same as `F`
instance = G(Book, author__name='Eistein')
# `M` receives a data mask and create a random string using it
# Known symbols: `_`, `#` or `-`
# To escape known symbols: `!`
instance = N(Book, address=M('Street ___, ### !- --'))
assert instance.address == 'Street TPA, 632 - BR'
# `C` copies data from one field to another
instance = N(Book, address_formatted=C('address'), address=M('Street ___, ### \- --'))
assert instance.address_formatted == 'Street TPA, 632 - BR'
# `teach` teaches DDF in how to build an instance
teach(Book, address=M('Street ___, ### !- --'))
instance = G(Book)
assert instance.address == 'Street TPA, 632 - BR'
# `P` print instance values for debugging
P(instance)
import ddf
ddf.__version__
from ddf import ddf_check_models
succeeded, errors = ddf_check_models()
succeeded, errors = ddf_check_models(print_csv=True)
succeeded, errors = ddf_check_models(csv_filename='ddf_compatibility_report.csv')

Metadata

Release files for django-dynamic-fixture 4.0.1

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-dynamic-fixture 4.0.1
File Size Uploaded Provenance
django-dynamic-fixture-4.0.1.tar.gz 44.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-dynamic-fixture 4.0.1
File Interpreter ABI Platform
django_dynamic_fixture-4.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 103.0 kB

Release files / django-dynamic-fixture-4.0.1.tar.gz

Download URL django-dynamic-fixture-4.0.1.tar.gz
Size 44.3 kB
Tags Source
SHA-256 checksum
How to use checksums
2a2197578b7702db8f5eed9ad704f6be33bac8bf0111c7c92f6063c2a4d02933
BLAKE2b-256 checksum
How to use checksums
4762d7ca06aece37b7c651b7ffe1aff15e89dfc18653e266af203c5ae9d5212b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Release files / django_dynamic_fixture-4.0.1-py3-none-any.whl

Download URL django_dynamic_fixture-4.0.1-py3-none-any.whl
Size 58.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0611b6dc594fb1bccad1fd94dade89cc8deca12385bc2763baded3e48322547
BLAKE2b-256 checksum
How to use checksums
5fcaf77782903f93a4ba42204dce89682c5de734d88002cefa6071f805697620
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.0

Security for django-dynamic-fixture 4.0.1

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.

Release history Release notifications | RSS feed

This release

4.0.1 This release

2 release files No provenance

1.5.0

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