#33348: Change API of assertFormError to take an actual form object
--------------------------------------+------------------------------------
     Reporter:  Baptiste Mispelon     |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  assigned
    Component:  Testing framework     |                  Version:  dev
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by Baptiste Mispelon):

 * has_patch:  0 => 1


Comment:

 PR is ready for review: https://github.com/django/django/pull/15179

 Overall the changes are backwards-compatible but there are some
 exceptions:

 1) The failure messages are now different
 2) The behavior of `errors=[]` is completely different
 3) The behavior in the case of multiple `errors` is different

 For 1), I don't know if our compatibility policy applies here. As noted in
 comment:1 the failure message were already prone to change arbitrarily as
 Django rendered more and more templates in its request/response cycle.

 For 2), the old implementation of `assertFormError` (and
 `assertFormsetError`) would **always** pass when using `errors=[]`. Even
 if the field had no errors, or even if the field was not present on the
 form. I'd argue that this is a prety nasty bug and fixing it actually
 caught an incorrect tests in Django's own test suite [1]

 For 3), the old implementation would only make sure that all the `errors`
 passed to `assertFormError` (and `assertFormsetError`) were present in the
 field's error. If the field happened to have extra errors the test would
 still pass. I changed that behavior so that the two lists must match
 exactly. This makes the implementation simpler (we can use a plain
 `assertEqual` and let Python give a nice diff in case of errors) and I
 think it's also more correct. The documentation wasn't very clear anyway
 so I think the change is acceptable.


 As part of the ticket, I also removed the undocumented ability to use
 `errors=None` as an equivalent to `errors=[]`. I don't really see the
 usecase for that "shortcut" and "one obvious way" something something.

 Finally, the PR adds a nicer `repr` for formsets, similar to what was done
 in #23167 (it made the tests easier to write).


 [1]
 
https://github.com/django/django/blob/2f73e5406d54cb8945e187eff302a3a3373350be/tests/admin_views/tests.py#L5558

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33348#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.ef34ecbbe4a323b72cff5cd8151d5803%40djangoproject.com.

Reply via email to