Skip to content

Instantly share code, notes, and snippets.

@riquellopes
Created May 27, 2012 18:48
Show Gist options
  • Save riquellopes/2815470 to your computer and use it in GitHub Desktop.
Save riquellopes/2815470 to your computer and use it in GitHub Desktop.
Simple mock urllib2.
from mock import Mock
class MockUrlLib(Mock):
def __init__(self, _file, _type='html', code=200, msg='OK', headers={'content-type': 'text/plain; charset=utf-8'}):
self.file_test = ("%s.%s" % (_file, _type))
self.code = code
self.msg = msg
self.headers = headers
def read(self):
handle = open(self.file_test)
html = "".join( handle )
return html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment