I am writting unittests and I am not able to understand how can I write unittest for reading a url.
def testing():
main_ip = "localhost"
another_url = "http://localhost:8086/test"
try:
response = urllib2.urlopen(another_url)
body = response.read()
if body:
main_ip = body.split(':')[0]
except urllib2.URLError as urlerr:
pass
return main_ip
I do not understand how can I mock or write unittest for urlopen and read?