def setUp(self): # Install the intercept from wsgi_intercept import httplib_intercept httplib_intercept.install() # Add the intercept for a nonexistant domain self.domain = "some_hopefully_nonexistant_domain" wsgi_intercept.add_intercept(self.domain, self.port, testing.create_fn) self.addCleanup(wsgi_intercept.remove_intercept, self.domain, self.port) # Cleanup with an intercept uninstall self.addCleanup(httplib_intercept.uninstall)
def setUp(self): # Install the intercept from wsgi_intercept import httplib_intercept httplib_intercept.install() # Add the intercept for a nonexistant domain self.domain = 'some_hopefully_nonexistant_domain' wsgi_intercept.add_intercept(self.domain, self.port, testing.create_fn) self.addCleanup(wsgi_intercept.remove_intercept, self.domain, self.port) # Cleanup with an intercept uninstall self.addCleanup(httplib_intercept.uninstall)
def install_opener(): # httplib patch from wsgi_intercept.httplib_intercept import install install() # requests' patch import wsgi_intercept from requests.packages.urllib3 import connectionpool connectionpool.old_http = connectionpool.HTTPConnection connectionpool.HTTPConnection = wsgi_intercept.WSGI_HTTPConnection connectionpool.old_https = connectionpool.HTTPSConnection connectionpool.HTTPSConnection = wsgi_intercept.WSGI_HTTPSConnection # we need settimeout() wsgi_intercept.wsgi_fake_socket.settimeout = lambda self, timeout: None
import os import urlparse from django.core.handlers.wsgi import WSGIHandler from django.core import management from wsgi_intercept import add_wsgi_intercept, httplib_intercept, \ mechanize_intercept, wsgi_fake_socket from pycon import settings os.environ['DJANGO_SETTINGS_MODULE'] = 'pycon.settings' wsgi_fake_socket.settimeout = lambda x, y: None httplib_intercept.install() def before_all(context): management.setup_environ(settings) from django.test.simple import DjangoTestSuiteRunner context.runner = DjangoTestSuiteRunner() host = context.host = 'localhost' port = context.port = 8765 add_wsgi_intercept(host, port, WSGIHandler) def browser_url(url): return urlparse.urljoin('http://%s:%d/' % (host, port), url) context.browser_url = browser_url
def https_install(): _saved_debuglevel, wsgi_intercept.debuglevel = wsgi_intercept.debuglevel, 1 httplib_intercept.install() wsgi_intercept.add_wsgi_intercept('some_hopefully_nonexistant_domain', 443, test_wsgi_app.create_fn)
def https_install(): _saved_debuglevel, wsgi_intercept.debuglevel = wsgi_intercept.debuglevel, 1 httplib_intercept.install() wsgi_intercept.add_wsgi_intercept('some_hopefully_nonexistant_domain', 443, test_wsgi_app.create_fn)