Git Product home page Git Product logo

django-dynamic-fixture's Introduction

Django Dynamic Fixture

Continuous Integration Status

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

Motivation

  • It is a TERRIBLE practice to use STATIC data in tests.
  • Create dynamic fixture for each model is boring and it produces a lot of replicated code.
  • It is a bad idea to use uncontrolled data in tests, like bizarre random data.

Basic Example of Usage

from django.db import models

class Author(models.Model):
    name = models.CharField(max_length=255)

class Book(models.Model):
    name = models.CharField(max_length=255)
    authors = models.ManyToManyField(Author)
from django.test import TestCase
from django_dynamic_fixture import G

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

Installation

pip install django-dynamic-fixture

or

1. Download zip file
2. Extract it
3. Execute in the extracted directory: python setup.py install

Upgrade:

pip install django-dynamic-fixture --upgrade --no-deps

Requirements

  • Python 2.6 or 2.7
  • Django 1.2, 1.3 or 1.4

Comparison with another fixture tools

  • We tried to use another fixture tools in a big Django project but the experience was not satisfactory.
  • Either they are incomplete, or bugged or it produces erratic tests, because they use random and uncontrolled data.
  • Also, the syntax of others tools is too verbose, which polutes the tests.
  • Complete, lean and practice documentation.
  • It is hard to debug tests with another tools.
  • List of other tools: http://djangopackages.com/grids/g/fixtures
  • The core of the tool is the algorithm, it is not the data generation as all other tools. That mean you can change the data generation logic as you want.

Features

  • Highly customizable: you can customize fields recursively
  • Deal with unique=True
  • Deal with cyclic dependencies (including self references)
  • Deal with many to many relationship (common M2M or M2M with additional data, i.e. through='table')
  • Deal with custom fields (specially if the custom field inherit of a django field)
  • It is supported for parallel tests
  • Deal with auto calculated attributes
  • It is easy to debug errors

Other goodies

  • Nose plugin that enable a setup for the entire suite (unittest2 includes only setups for class and module)
  • Nose plugin to count how many queries are executed by test
  • Command to count how many queries are executed to save any kind of model instance
  • FileSystemDjangoTestCase that facilitate to create tests for features that use filesystem.

Documentation links

FAQ

django-dynamic-fixture's People

Contributors

paulocheque avatar qris avatar sjhewitt avatar valdergallo avatar zvictor avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.