def test_login_required_success_normaluser(bottle_request): mock_controller = mock.Mock(__name__='controller') protected = mod.login_required()(mock_controller) bottle_request.fullpath = '/somewhere/' bottle_request.query_string = '' bottle_request.session.get.return_value = {'is_superuser': False} protected('test') mock_controller.assert_called_once_with('test')
def test_login_required_no_auth(bottle_request, bottle_redirect): mock_controller = mock.Mock(__name__='controller') protected = mod.login_required()(mock_controller) bottle_request.no_auth = True bottle_request.fullpath = '/somewhere/' bottle_request.query_string = '' bottle_request.user.is_authenticated = False protected('test') mock_controller.assert_called_once_with('test')
def test_login_required_not_logged_in_next_to(bottle_request, bottle_redirect): mock_controller = mock.Mock(__name__='controller') protected = mod.login_required(next_to='/go-here/')(mock_controller) bottle_request.no_auth = False bottle_request.fullpath = '/somewhere/' bottle_request.query_string = '' bottle_request.user.is_authenticated = False protected() bottle_redirect.assert_called_once_with('/login/?next=%2Fgo-here%2F') assert mock_controller.called is False
def test_login_required_forbidden(bottle_request, bottle_abort): mock_controller = mock.Mock(__name__='controller') protected = mod.login_required(superuser_only=True)(mock_controller) bottle_request.no_auth = False bottle_request.fullpath = '/somewhere/' bottle_request.query_string = '' bottle_request.user.is_authenticated = True bottle_request.user.is_superuser = False protected() bottle_abort.assert_called_once_with(403) assert mock_controller.called is False