コード例 #1
0
ファイル: util_test.py プロジェクト: uniteddiversity/indico
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')
コード例 #2
0
ファイル: util_test.py プロジェクト: uniteddiversity/indico
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')
コード例 #3
0
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()