Ticket #11958: contactform_errors.py

File contactform_errors.py, 518 bytes (added by brook, 15 years ago)

Simple test that prints out the errors of an invalid form

Line 
1from django import forms
2class ContactForm(forms.Form):
3 subject = forms.CharField(max_length=100)
4 message = forms.CharField()
5 sender = forms.EmailField()
6
7
8def test_contactform():
9 data = {
10 'subject':'my subject',
11 'message':'my message',
12 'sender':'invalid e-mail address',
13 }
14
15 f = ContactForm(data=data)
16
17 if not f.is_valid():
18 print f.errors # prints "<ul class="errorlist"><li>sender<ul class="errorlist"><li>Enter a valid e-mail address.</li></ul></li></ul>"
Back to Top