On 28 February 2015 at 10:07, Pranjal Yadav <godricglow@gmail.com> wrote:
Abhilash,
Thanks! it worked as you said. But renaming clean method is not conventional. I changed the names and it looks like 'clean_password_repeat' is good and that is the last input for that test as well, so I don't understand why but that works.
When you are concerned with cleaning only single field, you use clean_<field> method to do that. But when you have more than one fields to clean you put that under form's clean method. Also, form's clean method is run only after all the clean_<field> methods have already run.
Why does clean_repeat_password work? I don't understand! It may be because it just cleans 'repeat_password' , whose removal does not affect the creation of User model and hence your tests pass. For further details regarding this read here1
The 'except' part for 'clean_email' is not functioning as expected and I have already written the validation tests for that part as well.
Its not being used because it is not required at all. You don't have to clean an
EmailField, django forms does that automatically. They are simply CharFields
which are validated for email. And before you ask, I don't understand why
coverage shows that the part before 'except' is being executed. My guess is
that when email is valid, forms execute the clean_email
method, but when
its not, the ValidationError is raised before the execution reaches the
clean_email
.
-- thanks, Abhilash Raj