python - Django: block internet connection for testing purposes -
Text after "
I want to make sure my unit test does not try to connect to the Internet, there is an exception to increase Is there a way when they do?
There was a similar question, but the solution included all the socket connections proposed there are databases, which are not acceptable for Django testing.
One way to do this is to find out. You can paste in your settings
if 'test' in sys.argv:. During the trial # block Internet access urllib2 import httplib import httplib2 def _raise_http_error (* args, ** kwargs) Import: urllib2.URLError increased ("I asked not to use the Internet") class AngryHandler (urllib2.BaseHandler ): Handler_order = 1def default_open (auto, request): _raise_http_error () opener = urllib2.build_opener (AngryHandler) urllib2.install_opener (opener) _HTTPHandler = urllib2.HTTPHandler urllib2.HTTPHandler = AngryHandler httplib.HTTPConnection.connect = Lambda self : None themeplib.HTTPSConnection.connect = lambda self: none. .request = _raise_http_error
Comments
Post a Comment