def test_get_my_ip_from_default_site(self, mock_method): stub_ip = '123.45.67.89' response_mock = mock.NonCallableMock() response_mock.text = stub_ip mock_method.return_value = response_mock self.assertEqual(stub_ip, network_util.get_my_ip()) mock_method.assert_called_once_with(network_util.IP_DETECT_SITE)
def test_get_my_ip_from_user_specified_site(self, mock_method): stub_ip = '123.45.67.89' response_mock = mock.NonCallableMock() response_mock.text = stub_ip mock_method.return_value = response_mock ip_site = 'http://ip.stub.org' self.assertEqual(stub_ip, network_util.get_my_ip(ip_site=ip_site)) mock_method.assert_called_once_with(ip_site)
def _ip_updater_periodic_callback(self): if self.ob_ctx.enable_ip_checker: new_ip = network_util.get_my_ip() if not new_ip or new_ip == self.hostname: return self.ob_ctx.server_ip = new_ip self.hostname = new_ip if self.listener is not None: self.listener.set_ip_address(new_ip) self.dht.iterative_find(self.guid, [], 'findNode')
def test_get_my_ip_bad_response(self, mock_method): mock_method.return_value = None self.assertIsNone(network_util.get_my_ip())
def test_get_my_ip_failed_request(self, mock_method): self.assertIsNone(network_util.get_my_ip())