| | 6 | |
| | 7 | {{{#!python |
| | 8 | class ReproTestCase(TransactionTestCase): |
| | 9 | |
| | 10 | def test_when_login_view_raises_an_exception_password_is_not_in_the_500_email(self): # noqa: E501 |
| | 11 | password = '$0m3 P4$$w0rd' |
| | 12 | exception_email_html_body = self.get_500_email_html_for_login_error( |
| | 13 | username='some_user', password=password |
| | 14 | ) |
| | 15 | self.assertNotIn( |
| | 16 | member=password, container=exception_email_html_body) |
| | 17 | |
| | 18 | def get_500_email_html_for_login_error(self, username, password): |
| | 19 | # patch this methodd so AuthenticationForm.clean is |
| | 20 | # called which has local password variable |
| | 21 | login_view_raising_value_error = patch( |
| | 22 | 'django.contrib.auth.forms.authenticate', |
| | 23 | side_effect=ValueError('some error') |
| | 24 | ) |
| | 25 | |
| | 26 | self.goto_login_page() |
| | 27 | |
| | 28 | with TestClientNotRaisingExceptionButCapturing(self.client) as capture: # see implementation details in attachment |
| | 29 | with login_view_raising_value_error: |
| | 30 | self.submit_login(username=username, password=password) |
| | 31 | |
| | 32 | request = capture.get_captured_request() |
| | 33 | exc_type, exc_value, tb = capture.stored_exc_info |
| | 34 | # based on django.utils.log.AdminEmailHandler.emit |
| | 35 | reporter = ExceptionReporter( |
| | 36 | request=request, is_email=True, |
| | 37 | exc_type=exc_type, exc_value=exc_value, tb=tb) |
| | 38 | self.assertTrue(reporter.filter.is_active(request)) |
| | 39 | return reporter.get_traceback_html() |
| | 40 | }}} |