• Stars
    star
    389
  • Rank 110,500 (Top 3 %)
  • Language
    Python
  • License
    Other
  • Created over 12 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A complete library to create dynamic model instances for testing purposes.

Django Dynamic Fixture

Build Status Docs Status Coverage Status PyPI version PyPI - Python Version PyPI - Downloads

Latest version: 3.1.2 (Oct 2021)

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')

More Repositories

1

tornado-rest-handler

A simple Python Tornado handler that manage Rest requests automatically
Python
130
star
2

python-tornado-bootstrap

Python
44
star
3

epub-meta

Small Python library to read metadata information from an ePub (2 and 3) file.
Python
43
star
4

django-smart-autoregister

It is a Django tool that automatically configure the ModelAdmin classes of your application using some good patterns
Python
28
star
5

scala-design-patterns

Scala
26
star
6

python-rest-handler

Python
23
star
7

django-email-manager

A simple application to manage emails sent by a Django application.
Python
12
star
8

django-ip2geo

7
star
9

django-intruder

Django Intruder is a simple and unobtrusive application to intercept requests. It is useful to enable and disable features, for continuous deployment purpouses.
Python
4
star
10

swift-bootstrap

Swift
3
star
11

jquery-sharing

Simple plugin to provide a easy way to add links to share your website.
JavaScript
3
star
12

py-social

Python
2
star
13

python-bottle-bootstrap

Python
1
star
14

dillinger-bower

HTML
1
star
15

python-cardgameengine

Python
1
star
16

jquery-simpleinputlabel

One idea to avoid wasting screen space with labels is put the label as the initial text of a input.
JavaScript
1
star
17

grid.min

A minimum and lightweight responsive grid CSS library.
CSS
1
star
18

python-django-bootstrap

JavaScript
1
star
19

python-qassertions

Library with additional assertions to help creation of good automated tests, including some special assertion that create additional test cases automatically like assertValidation
Python
1
star
20

django-simple-workflow

1
star
21

python-html-objects

Python library that contains objects that represents HTML tags.
Python
1
star
22

jquery-simpleimagezoom

It is common that we want to highlight a image because a link or something. This can be done by a border change, link hover etc or a Image Zoom.
JavaScript
1
star