django-data-tests

A Django app for specifying validation tests on data in your database.


Keywords
django-data-tests
License
MIT
Install
pip install django-data-tests==0.6.0

Documentation

Django Data Tests

https://travis-ci.org/andrewbird2/django-data-tests.svg?branch=master

A Django app for specifying validation tests on data in your database.

Quickstart

Install Django Data Tests:

pip install django-data-tests

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'data_tests.apps.DataTestsConfig',
    ...
)

Add a data test to one of your existing models

from data_tests.registry import test_method
from django.db import models

class Cat(models.Model):
    ...

    def make_noise(self):
        return 'Miaow!'

    @test_method('Check the cat miaows appropriately')
    def check_cat_sound(self):
        noise = self.noise()
        if noise != 'Miaow!':
            return False, 'Cat made the wrong noise: %s' % noise
        else:
            return True

You can run your data tests with the management command

./manage.py rundatatests

Alternatively, run them whenever the object is saved in the admin

from django.contrib import admin
from data_tests.admin import DataTestsAdminMixin

class CatAdmin(DataTestsAdminMixin, admin.ModelAdmin):
    ...