def __init__(self, worker_init): self.worker_config = worker_init.worker_config self.input_queue = worker_init.input_queue self.output_queue = worker_init.output_queue self.urlopen = get_url_open() self.request_class = get_url_request() self.logger = worker_init.logger if not self.logger: # Get a new one! self.logger = get_logger() # We do this here to allow patching by gevent import socket self.timeout_exception = socket.timeout self.auth_header = None if self.worker_config.username and self.worker_config.password: base64string = unicode( base64.encodestring( '{0}:{1}'.format( self.worker_config.username, self.worker_config.password) .encode("utf-8")), "utf-8") self.auth_header = ("Authorization", "Basic {0}".format(base64string))
def test_301(self): urlopen = get_url_open() import socket url = self.get_url("/sub") response = open_url(urlopen, get_url_request(), url, 5, socket.timeout) self.assertEqual(200, response.status) self.assertTrue(response.is_redirect)
def test_200(self): urlopen = get_url_open() import socket url = self.get_url("/index.html") response = open_url(urlopen, get_url_request(), url, 5, socket.timeout) self.assertEqual(200, response.status) self.assertTrue(response.exception is None)
def test_404(self): urlopen = get_url_open() import socket url = self.get_url("/does_not_exist.html") response = open_url(urlopen, get_url_request(), url, 5, socket.timeout) self.assertEqual(404, response.status) self.assertTrue(response.exception is not None)
def test_404(self): urlopen = get_url_open() import socket url = self.get_url("/does_not_exist.html") response = open_url( urlopen, get_url_request(), url, 5, socket.timeout) self.assertEqual(404, response.status) self.assertTrue(response.exception is not None)
def __init__(self, worker_init): self.worker_config = worker_init.worker_config self.input_queue = worker_init.input_queue self.output_queue = worker_init.output_queue self.urlopen = get_url_open() self.request_class = get_url_request() self.logger = worker_init.logger if not self.logger: # Get a new one! self.logger = get_logger() # We do this here to allow patching by gevent import socket self.timeout_exception = socket.timeout self.auth_header = None if self.worker_config.username and self.worker_config.password: base64string = unicode( base64.encodestring('{0}:{1}'.format( self.worker_config.username, self.worker_config.password).encode("utf-8")), "utf-8") self.auth_header = ("Authorization", "Basic {0}".format(base64string))