Пример #1
0
 def test_connection_refused(self):
     connection = Connection(('localhost', 1))
     try:
         yield connection.fetch(Request.new('http://localhost:1/'))
     except ConnectionRefused:
         pass
     else:
         self.fail()
Пример #2
0
 def test_connection_reuse(self):
     connection = Connection('localhost', self._port)
     request = Request.new(self.get_url('/'))
     request.version = 'HTTP/1.0'
     response = yield connection.fetch(request)
     self.assertEqual(200, response.status_code)
     response = yield connection.fetch(request)
     self.assertEqual(200, response.status_code)
Пример #3
0
 def test_ssl_fail(self):
     connection = Connection('localhost', self.get_http_port())
     try:
         yield connection.fetch(Request.new(self.get_url('/')))
     except SSLVerficationError:
         pass
     else:
         self.fail()
Пример #4
0
 def test_read_timeout(self):
     connection = Connection('localhost', self._port, read_timeout=0.1)
     request = Request.new(self.get_url('/sleep_long'))
     try:
         yield connection.fetch(request)
     except NetworkError:
         pass
     else:
         self.fail()
Пример #5
0
 def test_connection_timeout(self):
     connection = Connection('1.0.0.0', 1, connect_timeout=0.1)
     try:
         yield connection.fetch(
             Request.new('http://1.0.0.0:1/'))
     except NetworkError:
         pass
     else:
         self.fail()
Пример #6
0
 def test_no_such_host(self):
     connection = Connection('wpull-no-exist.invalid', 80)
     try:
         yield connection.fetch(
             Request.new('http://wpull-no-exist.invalid'))
     except NetworkError:
         pass
     else:
         self.fail()
Пример #7
0
 def setUp(self):
     super().setUp()
     self.http_server = Server()
     self.http_server.start()
     self.http_server.started_event.wait(timeout=5.0)
     self._port = self.http_server.port
     self.connection = Connection(
         ('localhost', self._port),
         params=ConnectionParams(connect_timeout=2.0, read_timeout=60.0))
Пример #8
0
 def test_buffer_overflow(self):
     connection = Connection('localhost', self._port,
         connect_timeout=2.0, read_timeout=5.0, buffer_size=1000)
     request = Request.new(self.get_url('/buffer_overflow'))
     try:
         yield connection.fetch(request)
     except (ProtocolError, NetworkError):
         pass
     else:
         self.fail()
Пример #9
0
    def test_ignore_length(self):
        self.connection = Connection(
            ('localhost', self._port),
            params=ConnectionParams(keep_alive=False, ignore_length=True))

        response = yield self.connection.fetch(Request.new(
            self.get_url('/underrun')),
                                               recorder=DebugPrintRecorder())

        self.assertEqual(50, response.body.content_size)
Пример #10
0
 def test_ssl_fail(self):
     connection = Connection(
         ('localhost', self.get_http_port()),
         ssl_enable=True,
         params=ConnectionParams(
             ssl_options=dict(cert_reqs=ssl.CERT_REQUIRED,
                              ca_certs=self.get_ssl_options()['certfile'])))
     try:
         yield connection.fetch(Request.new(self.get_url('/')))
     except SSLVerficationError:
         pass
     else:
         self.fail()
Пример #11
0
    def test_underrun(self):
        self.connection = Connection(
            ('localhost', self._port),
            params=ConnectionParams(connect_timeout=2.0, read_timeout=1.0))

        for counter in range(3):
            print(counter)
            try:
                yield self.connection.fetch(
                    Request.new(self.get_url('/underrun')))
            except NetworkTimedOut:
                pass
            else:
                self.fail()
Пример #12
0
 def test_ssl_no_check(self):
     connection = Connection(('localhost', self.get_http_port()),
                             ssl_enable=True)
     yield connection.fetch(Request.new(self.get_url('/')))