On Thu, Jul 16, 2009 at 10:46 PM, Joshua Russo<josh.r.ru...@gmail.com> wrote: > > I want to test my forms but I'm not sure the best way to go about it. > It seems like it might be similar to views but I can't find much > discussion of form testing in any of the discussions about unit > testing. > > Any suggestions are much appreciated.
Well, a Form is just a class with a bunch of member functions - in your views you instantiate instances of the form and give it data, call is_valid() to validate and clean data. So a test is exactly that. Instantiate your form, give it some sample data, and assert that the data has either thrown an error (i.e., that is_valid() == False and form.errors is populated), or that form.cleaned_data contains the right output. Keep in mind that you don't need to test the core behaviour - Django's test suite will check that a simple integer field will reject character input, etc. All you need to test is your own local extensions, like clean_* methods. Yours Russ Magee %-) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---