On 9/9/07, Amit Upadhyay <[EMAIL PROTECTED]> wrote:
> Python unittest TestCase objects have a lot of helper functions like
> assert_(), failUnless(), assertEqual(), assertNotEqual() and so on[1]. If we
> had a similar set of helper functions, possibly with more pythonic names,
> newform validation functions could be written a little more succinctly.
>
> def clean_password2(self):
> if self.clean_data['password1'] != self.clean_data['password2']:
> raise ValidationError(u'Please make sure your passwords match.')
> return self.clean_data['password2']
>
> can become
>
> def clean_password2(self):
> assert_equal(self.clean_data['password1'],
> self.clean_data['password2', "Please make sure your passwords match."
> return self.clean_data['password2']
I think a series of helpers for newforms validation is a reasonable
idea. I have a few comments about the exact form of your suggestions:
- I'm not wild about the deviation from the established camelCase
naming convention. The tests are called assertEqual, assertRaises etc
in TestCase; although Django generally uses underscores rather than
camelCase, I think there would be more value in maintaining
similarity.
- I'm also inclined to continue the similarities, and make the
assertion functions members on BaseForm. This would allow a
significant simplification of your proposal, as the data locations
(i.e., self.cleaned_data) can be implied.
So - as a result of those suggestions, the helpers would look more like:
def clean_password2(self):
self.assertEqual('password1','password2','Please make sure...')
return self.clean_data['password2']
Thoughts?
Yours,
Russ Magee %-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---