def test_netrc_file_missing_error(self, MockOsPath): MockOsPath.exists.return_value = False netrc = Netrc() with self.assertRaises(netrc.NetrcError) as exc: netrc._ensure_loaded() assert str( exc.exception) == 'A ~/.netrc file is required to authenticate'
def test_netrc_success(self, MockOsPath): with patch('pants.util.netrc.NetrcDb') as mock_netrc: instance = mock_netrc.return_value instance.hosts = {'host': ('user', 'user', 'passw0rd')} instance.authenticators.return_value = ('user', 'user', 'passw0rd') netrc = Netrc() netrc._ensure_loaded()
def test_netrc_success(self, MockOsPath): with patch("pants.util.netrc.NetrcDb") as mock_netrc: instance = mock_netrc.return_value instance.hosts = {"host": ("user", "user", "passw0rd")} instance.authenticators.return_value = ("user", "user", "passw0rd") netrc = Netrc() netrc._ensure_loaded()
def test_netrc_file_missing_error(self, MockOsPath): MockOsPath.exists.return_value = False netrc = Netrc() with self.assertRaises(netrc.NetrcError) as exc: netrc._ensure_loaded() assert str(exc.exception) == 'A ~/.netrc file is required to authenticate'
def _credentials(self, repository): netrc = Netrc() return (netrc.getusername(repository), netrc.getpassword(repository))
def netrc(self, netrc_contents): m = mock_open(read_data=netrc_contents) with patch('__builtin__.open', m): netrc = Netrc() yield netrc
def netrc(self, netrc_contents): m = mock_open(read_data=netrc_contents) with patch("builtins.open", m): netrc = Netrc() yield netrc
def netrc(self, netrc_contents): m = mock_open(read_data=netrc_contents) open_builtin_name = 'builtins.open' if PY3 else '__builtin__.open' with patch(open_builtin_name, m): netrc = Netrc() yield netrc