示例#1
0
def test_validate_credentials_raises_user_error_on_unauthorized():
    pypirc = PyPIRC()
    pypirc.set_server_username('http://sentinel.uri', 'Aladdin')  # RFC 1945
    pypirc.set_server_password('http://sentinel.uri', 'open sesame')
    unauthorized = HTTPError('http://sentinel.uri', 401, 'basic auth failed',
                             {}, None)
    with patch(_open_director_open, side_effect=unauthorized):
        with raises(UserError) as exc:
            pypirc.validate_credentials('http://sentinel.uri')
    assert exc.value.msg == UserError('Invalid PyPi credentials',
                                      'http://sentinel.uri',
                                      'basic auth failed').msg
示例#2
0
def test_validate_credentials_raises_on_unexpected_error():
    pypirc = PyPIRC()
    pypirc.set_server_username('http://sentinel.uri', 'Aladdin')  # RFC 1945
    pypirc.set_server_password('http://sentinel.uri', 'open sesame')
    internal_error = HTTPError('http://sentinel.uri', 500,
                               'Internal Server Error', {}, cStringIO('oops'))
    with patch(_open_director_open, side_effect=internal_error):
        with raises(IOError) as exc:
            pypirc.validate_credentials('http://sentinel.uri')
    assert repr(exc.value) == repr(
        IOError('Unexpected status from PyPi', 'http://sentinel.uri', 500,
                'Internal Server Error: oops'))
示例#3
0
def test_validate_credentials_raises_on_unexpected_success():
    pypirc = PyPIRC()
    pypirc.set_server_username('http://sentinel.uri', 'Aladdin')  # RFC 1945
    pypirc.set_server_password('http://sentinel.uri', 'open sesame')
    success = addinfourl(cStringIO('great'), 'OK', 'http://sentinel.uri')
    success.code = 200
    success.msg = 'OK'
    with patch(_open_director_open, return_value=success):
        with raises(IOError) as exc:
            pypirc.validate_credentials('http://sentinel.uri')
    assert repr(exc.value) == repr(
        IOError('Unexpected status from PyPi', 'http://sentinel.uri', 200,
                'OK: great'))
示例#4
0
def test_validate_credentials_raises_on_unexpected_error():
    pypirc = PyPIRC()
    pypirc.set_server_username('http://sentinel.uri', 'Aladdin')  # RFC 1945
    pypirc.set_server_password('http://sentinel.uri', 'open sesame')
    internal_error = HTTPError('http://sentinel.uri', 500,
                               'Internal Server Error', {}, cStringIO('oops'))
    with patch(_open_director_open, side_effect=internal_error):
        with raises(IOError) as exc:
            pypirc.validate_credentials('http://sentinel.uri')
    assert repr(exc.value) == repr(IOError('Unexpected status from PyPi',
                                           'http://sentinel.uri', 500,
                                           'Internal Server Error: oops'))
示例#5
0
def test_validate_credentials_raises_user_error_on_unauthorized():
    pypirc = PyPIRC()
    pypirc.set_server_username('http://sentinel.uri', 'Aladdin')  # RFC 1945
    pypirc.set_server_password('http://sentinel.uri', 'open sesame')
    unauthorized = HTTPError('http://sentinel.uri', 401, 'basic auth failed',
                             {}, None)
    with patch(_open_director_open, side_effect=unauthorized):
        with raises(UserError) as exc:
            pypirc.validate_credentials('http://sentinel.uri')
    assert exc.value.msg == UserError('Invalid PyPi credentials',
                                      'http://sentinel.uri',
                                      'basic auth failed').msg
示例#6
0
def test_validate_credentials_raises_on_unexpected_success():
    pypirc = PyPIRC()
    pypirc.set_server_username('http://sentinel.uri', 'Aladdin')  # RFC 1945
    pypirc.set_server_password('http://sentinel.uri', 'open sesame')
    success = addinfourl(cStringIO('great'), 'OK', 'http://sentinel.uri')
    success.code = 200
    success.msg = 'OK'
    with patch(_open_director_open, return_value=success):
        with raises(IOError) as exc:
            pypirc.validate_credentials('http://sentinel.uri')
    assert repr(exc.value) == repr(IOError('Unexpected status from PyPi',
                                           'http://sentinel.uri', 200,
                                           'OK: great'))
示例#7
0
def test_validate_credentials():
    pypirc = PyPIRC()
    pypirc.set_server_username('http://sentinel.uri', 'Aladdin')  # RFC 1945
    pypirc.set_server_password('http://sentinel.uri', 'open sesame')
    bad_request = HTTPError('http://sentinel.uri', 400, 'Bad Request', {},
                            cStringIO(''))
    with patch(_open_director) as OpenerDirector:
        OpenerDirector.return_value.open.side_effect = bad_request
        pypirc.validate_credentials('http://sentinel.uri')
    request = next(
        req for (req, ), _ in OpenerDirector.return_value.open.call_args_list)
    assert request.get_method() == 'GET'
    assert request.get_full_url(
    ) == 'http://sentinel.uri?%3Aaction=file_upload'
    auth = next(handler for (
        handler, ), _ in OpenerDirector.return_value.add_handler.call_args_list
                if isinstance(handler, HTTPBasicAuthHandler))
    assert (auth.passwd.find_user_password(
        'pypi', 'http://sentinel.uri?%3A'
        'action=file_upload') == ('Aladdin', 'open sesame'))
示例#8
0
def test_validate_credentials():
    pypirc = PyPIRC()
    pypirc.set_server_username('http://sentinel.uri', 'Aladdin')  # RFC 1945
    pypirc.set_server_password('http://sentinel.uri', 'open sesame')
    bad_request = HTTPError('http://sentinel.uri', 400, 'Bad Request', {},
                            cStringIO(''))
    with patch(_open_director) as OpenerDirector:
        OpenerDirector.return_value.open.side_effect = bad_request
        pypirc.validate_credentials('http://sentinel.uri')
    request = next(req for (req,), _
                   in OpenerDirector.return_value.open.call_args_list)
    assert request.get_method() == 'GET'
    assert request.get_full_url() == 'http://sentinel.uri?%3Aaction=file_upload'
    auth = next(handler for (handler,), _
                in OpenerDirector.return_value.add_handler.call_args_list if
                isinstance(handler, HTTPBasicAuthHandler))
    assert (auth.passwd.find_user_password('pypi', 'http://sentinel.uri?%3A'
                                           'action=file_upload') ==
            ('Aladdin', 'open sesame'))