Ejemplo n.º 1
0
 def test_urllib_url_error(self):
     os_error = OSError(errno.ECONNREFUSED, os.strerror(errno.ECONNREFUSED))
     socket_error = exc.socket.error(os_error)
     error = exc.urllib2.URLError(socket_error)
     e = exc.HTTPClientError(self.req, error)
     expected = "GET on http://localhost/path failed with '%s'" % os_error
     self.assertEquals(str(e), expected)
Ejemplo n.º 2
0
 def test_urllib_http_error(self):
     error = exc.urllib2.HTTPError(self.req.get_full_url(), 401,
                                   'Unauthorized', {},
                                   StringIO("<h2>some error</h2>"))
     e = exc.HTTPClientError(self.req, error)
     expected = "GET on http://localhost/path returned " \
                "'401' with '<h2>some error</h2>'"
     self.assertEquals(str(e), expected)
Ejemplo n.º 3
0
 def test_urllib_http_error_with_json(self):
     body = {'reason': 'Invalid Token'}
     data = json.dumps(body)
     error = exc.urllib2.HTTPError(self.req.get_full_url(), 401,
                                   'Unauthorized', {}, StringIO(data))
     e = exc.HTTPClientError(self.req, error)
     expected = "GET on http://localhost/path returned " \
                "'401' with 'Invalid Token'"
     self.assertEquals(str(e), expected)
     body = {'message': 'You supplied an invalid token.'}
     data = json.dumps(body)
     error = exc.urllib2.HTTPError(self.req.get_full_url(), 401,
                                   'Unauthorized', {}, StringIO(data))
     e = exc.HTTPClientError(self.req, error)
     expected = "GET on http://localhost/path returned " \
                "'401' with 'You supplied an invalid token.'"
     self.assertEquals(str(e), expected)
Ejemplo n.º 4
0
 def test_bad_status_line_error(self):
     error = httplib.BadStatusLine('')
     e = exc.HTTPClientError(self.req, error)
     expected = "GET on http://localhost/path failed " \
                "with '%s'" % error.__class__.__name__
     self.assertEquals(str(e), expected)
Ejemplo n.º 5
0
 def test_socket_timeout(self):
     error = exc.socket.timeout('timed out')
     e = exc.HTTPClientError(self.req, error)
     expected = 'GET on http://localhost/path failed with socket timeout'
     self.assertEquals(str(e), expected)