A full library to create dynamic model instances for testing purposes.
Slowing down. Last release over 3 years ago, little activity since. Fine for existing code; think twice for a new project.
Consider insteadmodel-bakeryPythie’s Index: 912.1M downloads/moCompare →
pip install django-dynamic-fixtureDjango Dynamic Fixture
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'