def test_get_oauth_user_oauth_error(mocker): request = mocker.patch('indico.web.util.request') request.headers = {'Authorization': 'Bearer foo'} acquire_token = mocker.patch.object(IndicoResourceProtector, 'acquire_token') acquire_token.side_effect = InsufficientScopeError() with pytest.raises(IndicoAuthlibHTTPError) as exc_info: get_oauth_user('whatever') assert 'requires higher privileges than provided' in str(exc_info.value) acquire_token.assert_called_with('whatever')
def test_get_oauth_user_oauth(mocker, dummy_user): request = mocker.patch('indico.web.util.request') request.headers = {'Authorization': 'Bearer foo'} acquire_token = mocker.patch.object(IndicoResourceProtector, 'acquire_token') acquire_token.return_value.user = dummy_user assert get_oauth_user('whatever') == dummy_user acquire_token.assert_called_with('whatever')
def test_get_oauth_user_no_token(mocker, headers): request = mocker.patch('indico.web.util.request') request.headers = headers acquire_token = mocker.patch.object(IndicoResourceProtector, 'acquire_token') assert get_oauth_user('whatever') is None acquire_token.assert_not_called()