diff --git a/noipy/utils.py b/noipy/utils.py index 60c6ec8..deec47e 100644 --- a/noipy/utils.py +++ b/noipy/utils.py @@ -9,8 +9,6 @@ import requests -HTTPBIN_URL = 'https://httpbin.org/ip' - try: input = raw_input except NameError: @@ -21,10 +19,10 @@ def read_input(message): return input(message) -def get_ip(): +def get_ip(httpbin_url): """Return machine's origin IP address.""" try: - r = requests.get(HTTPBIN_URL) + r = requests.get(httpbin_url) return r.json()['origin'] if r.status_code == 200 else None except requests.exceptions.ConnectionError: return None diff --git a/test/test_noipy.py b/test/test_noipy.py index fe72800..6d0602c 100644 --- a/test/test_noipy.py +++ b/test/test_noipy.py @@ -31,14 +31,12 @@ def tearDown(self): shutil.rmtree(self.test_dir) def test_get_ip(self): - ip = utils.get_ip() + ip = utils.get_ip('https://httpbin.org/ip') self.assertTrue(re.match(VALID_IP_REGEX, ip), 'get_ip() failed.') # monkey patch for testing (forcing ConnectionError) - utils.HTTPBIN_URL = 'http://example.nothing' - - ip = utils.get_ip() + ip = utils.get_ip('http://example.nothing') self.assertTrue(ip is None, 'get_ip() should return None. IP={}'.format(ip)) def test_get_dns_ip(self):