def test_current_ip_exception(self, mock_get): """ Test that 'get_current_ip' raises TorIpError when an IP isn't returned. """ mock_response = Mock() mock_response.ok = False mock_get.return_value = mock_response tor_ip_changer = TorIpChanger() with self.assertRaises(TorIpError): tor_ip_changer.get_current_ip()
def test_current_ip(self, mock_get_response_text, mock_get): """ Test that 'real_ip' is obtained routing the request through Tor/Privoxy. """ mock_get_response_text.return_value = "9.9.9.9" tor_ip_changer = TorIpChanger() current_ip = tor_ip_changer.get_current_ip() self.assertEqual(current_ip, mock_get_response_text.return_value) mock_get.assert_called_once_with(ICANHAZIP, proxies={"http": LOCAL_HTTP_PROXY})