django-forms

Testing

Introduction#

One core feature of Django is unit tests.

This topic intends to bring a complete documentation on how to test forms.

Simple Test

from django.test import TestCase
from myapp.forms import MyForm

class MyAppTests(TestCase):
    def test_forms(self):
        form_data = {'field1': 'fieldvalue1'}
        form = MyForm(data=form_data)
        self.assertTrue(form.is_valid())

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow