def test_login_failure_log_exception(self): """If login_failure is passed an exception, it should log it.""" excpt = BrowserIDException(Exception('hsakjw')) with patch('django_browserid.views.logger.error') as logger_error: views.Verify().login_failure(excpt) logger_error.assert_called_with(excpt)
def test_authenticate_browserid_exception(authenticate): # If authenticate raises a BrowserIDException, redirect to the failure URL. err = BrowserIDException('test') authenticate.side_effect = err response = verify('post', failure_url='/fail', assertion='asdf') assert response.status_code == 302 assert response['Location'].endswith('/fail?bid_login_failed=1')
def test_authenticate_browserid_exception(self, authenticate, logger_error): # If authenticate raises a BrowserIDException, return a failure response. excpt = BrowserIDException(Exception('hsakjw')) authenticate.side_effect = excpt with patch.object(views.Verify, 'login_failure') as mock_failure: response = self.verify('post', assertion='asdf') eq_(response, mock_failure.return_value) mock_failure.assert_called_with(excpt)
def test_authenticate_browserid_exception(self, authenticate, logger_error): # If authenticate raises a BrowserIDException, redirect to the failure URL. excpt = BrowserIDException(Exception('hsakjw')) authenticate.side_effect = excpt response = self.verify('post', failure_url='/fail', assertion='asdf') assert response.status_code == 302 assert response['Location'].endswith('/fail?bid_login_failed=1') logger_error.assert_called_with(excpt)
def test_authenticate_browserid_exception(self, authenticate, logger_error): # If authenticate raises a BrowserIDException, return a failure response. excpt = BrowserIDException(Exception('hsakjw')) authenticate.side_effect = excpt with self.settings(LOGIN_REDIRECT_URL_FAILURE='/fail'): response = self.verify('post', assertion='asdf') eq_(response.status_code, 403) self.assert_json_equals(response.content, {'redirect': '/fail?bid_login_failed=1'}) logger_error.assert_called_with(excpt)