Opened 9 years ago
Closed 4 years ago
#24782 closed New feature (wontfix)
Add TestCase.assertFormValid
Reported by: | Marc Tamlyn | Owned by: | David Smith |
---|---|---|---|
Component: | Testing framework | Version: | dev |
Severity: | Normal | Keywords: | forms |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
In the case the form is actually valid, then assertFormValid(form)
is no different to assertTrue(form.is_valid)
, however when the assertion fails it should print some helpful output about which fields have validation errors and what those errors are. Even just outputting errors.as_json
would help a lot. I've implemented code along the lines of this many times.
Change History (13)
comment:1 by , 9 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 9 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:3 by , 9 years ago
Has patch: | set |
---|---|
Needs documentation: | set |
Needs tests: | set |
comment:4 by , 9 years ago
Easy pickings: | unset |
---|---|
Needs documentation: | unset |
Needs tests: | unset |
Patch needs improvement: | set |
comment:5 by , 9 years ago
Owner: | changed from | to
---|
comment:6 by , 9 years ago
Patch needs improvement: | unset |
---|
I have opened a new PR: https://github.com/django/django/pull/5595
comment:8 by , 9 years ago
Patch needs improvement: | unset |
---|
comment:9 by , 9 years ago
Patch needs improvement: | set |
---|
There are comments on the new pull request for improvement.
comment:10 by , 4 years ago
Owner: | changed from | to
---|
comment:11 by , 4 years ago
Patch needs improvement: | unset |
---|
comment:12 by , 4 years ago
Patch needs improvement: | set |
---|
comment:13 by , 4 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
Triage Stage: | Accepted → Unreviewed |
After detailed analysis provided by David we decided to close this as wontfix
:
- expecting a user to pass in all the requirements to pass the
ValidationError
equality test is too hard to be useful, - the currently proposed
code
method isn't that robust, there may be too many caveats for it to be useful, e.g. custom user errors generated where passwords don't match are unlikely to have a code passed into theValidationError
, - if it's just pass/fail that isn't much benefit from
self.assertIs(form.is_valid(), True)
,
In the end, this isn't worth adding extra functions.
See comment from Marc on the pull request for methods to be added.