On Jul 17, 10:50 am, Joshua Russo <josh.r.ru...@gmail.com> wrote: > On Jul 16, 11:11 pm, Russell Keith-Magee <freakboy3...@gmail.com> > wrote: > > > > > 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 %-) > > Thanks. I'm guess I need to take a closer look at the forms > functionality. I don't think I'm using it properly. This is my first > Django project and I guess I don't always know enough of what I'm > asking about to ask a full question. > > Thanks for the input.
Some time ago I wrote down my experience on testing, including testing forms: http://viktornagy.com/blog/2009/05/24/what-test-django/ moreover, I would recommend to check out the tests of some existing projects, that might give you some clues on how to test forms, views, models, etc. V --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---