@@ -41,10 +41,39 @@ def test_get_ip(self):
4141 except Exception as ex :
4242 self .assertIsNone (ex , "get_ip() failed." )
4343
44+ # monkey patch for testing (forcing HTTP 404)
45+ utils .IP6ONLY_URL = "http://ip6only.me/bad"
46+ ip = utils .get_ip ()
47+ self .assertIsNotNone (ip )
48+ self .assertNotIn (',' , ip )
49+
4450 # monkey patch for testing (forcing ConnectionError)
45- utils .HTTPBIN_URL = "http://example.nothing"
46- utils .IP4ONLY_URL = "http://example.nothing"
4751 utils .IP6ONLY_URL = "http://example.nothing"
52+ ip = utils .get_ip ()
53+ self .assertIsNotNone (ip )
54+ self .assertNotIn (',' , ip )
55+
56+ # monkey patch for testing (forcing HTTP 404)
57+ utils .IP4ONLY_URL = "http://ip4only.me/bad"
58+ ip = utils .get_ip ()
59+ self .assertIsNotNone (ip )
60+ self .assertNotIn (',' , ip )
61+
62+ # monkey patch for testing (forcing ConnectionError)
63+ utils .IP4ONLY_URL = "http://example.nothing"
64+
65+ ip = utils .get_ip ()
66+ self .assertIsNotNone (ip )
67+ self .assertNotIn (',' , ip )
68+
69+ # monkey patch for testing (forcing HTTP 404)
70+ utils .HTTPBIN_URL = "https://httpbin.org/bad"
71+
72+ ip = utils .get_ip ()
73+ self .assertTrue (ip is None , "get_ip() should return None. IP=%s" % ip )
74+
75+ # monkey patch for testing (forcing ConnectionError)
76+ utils .HTTPBIN_URL = "http://example.nothing"
4877
4978 ip = utils .get_ip ()
5079 self .assertTrue (ip is None , "get_ip() should return None. IP=%s" % ip )
@@ -54,11 +83,18 @@ def test_get_dns_ip(self):
5483
5584 self .assertEqual (ip , "127.0.0.1" , "get_dns_ip() failed." )
5685
57- ip = utils .get_dns_ip ("http://example.nothing" )
86+ ip = utils .get_dns_ip ("ip4only.me" )
87+ self .assertIsNotNone (ip , "get_dns_ip() should resolve IPv4" )
88+
89+ ip = utils .get_dns_ip ("ip6only.me" )
90+ self .assertIsNotNone (ip , "get_dns_ip() should resolve IPv6" )
91+
92+ ip = utils .get_dns_ip ("example.nothing" )
5893 self .assertTrue (ip is None , "get_dns_ip() should return None. IP=%s"
5994 % ip )
6095
6196
97+
6298class PluginsTest (unittest .TestCase ):
6399
64100 def setUp (self ):
0 commit comments