[Answer]-Django Form Clean Method Test Error

1๐Ÿ‘

โœ…

My guess is that in CreateAuditForm.clean, useris None because clean_user raised a ValidationError. The ValidationError comes from the fact that the user does not have the groups he needs.

Another issue I see is that to test equality between model instances in Django, you should not use primary keys but test using the instances directly, using == and not is. (See https://stackoverflow.com/a/13650309/1644198 for more information on is and ==)

Example:

if user != userwebsite.user:
    # etc...
๐Ÿ‘คaumo

Leave a comment