I need to test a function that needs to query a page on an external server using urllib.urlopen (it also uses urllib.urlencode). The server could be down, the page could cha
Adding onto Clint Miller's answer, to do this I had to create a fake class that implements a read method like this:
class FakeURL:
def read(foo):
return '{"some":"json_text"}'
Then to stub out urllib2.open:
# Stub out urllib2.open.
def dummy_urlopen(foo, bar, baz):
return FakeURL()
urllib2.urlopen = dummy_urlopen