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'))
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'))
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'))
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'))
def test_get_mirror_config(): pypi = CluePyPIAPI('http://example.com') mirror_cfg = cStringIO(MIRROR_CONFIG) file_dict = {'mirror.cfg': mirror_cfg} with ExitStack() as stack: stack.enter_context(_patch_open(file_dict=file_dict)) stack.enter_context(patch("os.path.isfile", return_value=True)) cfg = pypi.get_mirror_config('mirror.cfg') assert len(cfg) == 2 for c in cfg: assert c['target_host'] in ('foohost', 'barhost') if c['target_host'] == 'foohost': assert c['target_dir'] == '/path/to/foodir' else: assert c['target_dir'] == '/path/to/bardir'
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'))
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'))
def parse_cfg(setup_cfg): parser = configparser.ConfigParser() parser.readfp(cStringIO(setup_cfg)) return parser
def mock_clue(): return Mock(return_value=cStringIO(clue_page))
def read(self, filenames): if filenames == "setup.cfg": ConfigParser.readfp(self, cStringIO(content)) else: ConfigParser.read(self, filenames)