Skip to main content

Testing django without all the fixtures

Project description

milkman is an open source fixture replacement for Django testing.

Instead of maintaining scores of fixtures, whether they be generated, dumped, or managed semi-dynamically, it can still generate a lot of code that is not even test code. Furthermore, this tends to be brittle and hard to maintain.

The genius of milkman is that it randomly generates data for all the fields on a particular object, while at the same time allowing the test writer to override any particular field with their own data when determinate fields are needed for a test.

Example:

from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import TestCase, Client

from milkman.dairy import milkman

from app.models import Library, Book, Author


class LibraryTest(TestCase):

    def setUp(self):
        self.user = milkman.deliver(User)
        self.user.set_password("letmein")
        self.user.save()

        self.user2 = milkman.deliver(User)
        self.user2.set_password("letmein")
        self.user2.save()

        self.library = milkman.deliver(Library)
        self.book = milkman.deliver(Book)
        self.author = milkman.deliver(Author, lastname="Lewis")

        self.client = Client()
        self.client.login(username=self.user.username, password="letmein")

        self.url = reverse("book", args=[self.library.id, self.book.id])

    def tearDown(self):
        self.user.delete()
        self.user2.delete()
        self.library.delete()
        self.book.delete()
        self.author.delete()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

milkman-0.4.4.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file milkman-0.4.4.tar.gz.

File metadata

  • Download URL: milkman-0.4.4.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for milkman-0.4.4.tar.gz
Algorithm Hash digest
SHA256 57d7e780859309f488efd726e052591ed13d431704a17c28f0d5efd47c313e3b
MD5 19f7d854eabe46df4f3e661261b590b9
BLAKE2b-256 f311c7b2e941bc576e53e1a3b042597bc5cf51537949e343fbf6c7df1ee7d3fa

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page