I’m trying to understand why the following test does not fail. In this simplified example there is a required field ‘foobar’ on the Story model. The test builds a form on that model and supplies it with incomplete data. Why is the form considered valid by the test?
# models.py
class Story(models.Model):
headline = models.CharField(max_length=120)
foobar = models.CharField(max_length=100)
# test.py
from django.test import TestCase
from news.models import Story
from django import forms
class StoryForm(forms.Form):
class Meta:
model = Story
class FormTestCase(TestCase):
def test_form(self):
post_dict = {'headline': 'Test Title'}
form = StoryForm(post_dict)
self.assertTrue(form.is_valid())
should your
StoryFormbe inheriting fromforms.ModelForm(notforms.Form)?