(self)
| 1569 | password2 = CharField(widget=PasswordInput) |
| 1570 | |
| 1571 | def clean(self): |
| 1572 | # Test raising a ValidationError as NON_FIELD_ERRORS. |
| 1573 | if ( |
| 1574 | self.cleaned_data.get("password1") |
| 1575 | and self.cleaned_data.get("password2") |
| 1576 | and self.cleaned_data["password1"] != self.cleaned_data["password2"] |
| 1577 | ): |
| 1578 | raise ValidationError("Please make sure your passwords match.") |
| 1579 | |
| 1580 | # Test raising ValidationError that targets multiple fields. |
| 1581 | errors = {} |
| 1582 | if self.cleaned_data.get("password1") == "FORBIDDEN_VALUE": |
| 1583 | errors["password1"] = "Forbidden value." |
| 1584 | if self.cleaned_data.get("password2") == "FORBIDDEN_VALUE": |
| 1585 | errors["password2"] = ["Forbidden value."] |
| 1586 | if errors: |
| 1587 | raise ValidationError(errors) |
| 1588 | |
| 1589 | # Test Form.add_error() |
| 1590 | if self.cleaned_data.get("password1") == "FORBIDDEN_VALUE2": |
| 1591 | self.add_error(None, "Non-field error 1.") |
| 1592 | self.add_error("password1", "Forbidden value 2.") |
| 1593 | if self.cleaned_data.get("password2") == "FORBIDDEN_VALUE2": |
| 1594 | self.add_error("password2", "Forbidden value 2.") |
| 1595 | raise ValidationError("Non-field error 2.") |
| 1596 | |
| 1597 | return self.cleaned_data |
| 1598 | |
| 1599 | f = UserRegistration(auto_id=False) |
| 1600 | self.assertEqual(f.errors, {}) |
nothing calls this directly
no test coverage detected