Ejemplo n.º 1
0
    def test_download_simple(self):
        # Test that the download function can download a file over HTTP.
        value = "Some random string here."

        def _handler(*args):
            return _SimpleHandler(value, *args)

        def _verifier(filelike):
            return filelike.read() == value

        with _test_http_server(_handler) as server:
            with download.get(server.url('/'), dict(
                    verifier=_verifier, tries=1)) as data:
                self.assertEqual(value, data.read())
Ejemplo n.º 2
0
    def test_download_simple(self):
        # Test that the download function can download a file over HTTP.
        value = b"Some random string here."

        def _handler(*args):
            return _SimpleHandler(value, *args)

        def _verifier(filelike):
            return filelike.read() == value

        with _test_http_server(_handler) as server:
            with download.get(server.url('/'), dict(verifier=_verifier,
                                                    tries=1)) as data:
                self.assertEqual(value, data.read())
Ejemplo n.º 3
0
    def test_download_restart_from_scratch(self):
        # Test that the download function can handle restarting from scratch
        # if the server doesn't support byte range requests.
        value = "Some random string here."

        # The server initially doesn't give the whole file, but eventually
        # will.
        max_len = _MaxLenFunc(4, 4)

        def _handler(*args):
            return _DroppingHandler(value, max_len, False, *args)

        def _verifier(filelike):
            v = filelike.read() == value
            return v

        with _test_http_server(_handler) as server:
            with download.get(server.url('/'), dict(
                    verifier=_verifier, tries=(len(value) / 4 + 1))) as data:
                self.assertEqual(value, data.read())
Ejemplo n.º 4
0
    def test_download_restart(self):
        # Test that the download function can handle restarting, and fetching
        # a file as a series of smaller byte ranges.
        value = "Some random string here."

        # The server will only return 4-byte chunks, but it should be possible
        # to download the whole file eventually.
        max_len = _MaxLenFunc(4, 0)

        def _handler(*args):
            return _DroppingHandler(value, max_len, True, *args)

        def _verifier(filelike):
            v = filelike.read() == value
            return v

        with _test_http_server(_handler) as server:
            with download.get(server.url('/'), dict(
                    verifier=_verifier, tries=(len(value) / 4 + 1))) as data:
                self.assertEqual(value, data.read())
Ejemplo n.º 5
0
    def test_download_limited_retries(self):
        # In the case that the server is so thoroughly broken that it is not
        # possible to download the file (or would take an inordinate amount of
        # time), the download process should cap the maximum number of tries
        # to a finite value.
        value = "Some random string here."

        # The server just gives back the same 4 bytes over and over.
        max_len = _MaxLenFunc(4, 0)

        def _handler(*args):
            return _DroppingHandler(value, max_len, False, *args)

        def _verifier(filelike):
            v = filelike.read() == value
            return v

        with _test_http_server(_handler) as server:
            with self.assertRaises(download.DownloadFailedError):
                with download.get(server.url('/'), dict(verifier=_verifier,
                                                        tries=10)) as data:
                    data.read()
Ejemplo n.º 6
0
    def test_download_limited_retries(self):
        # In the case that the server is so thoroughly broken that it is not
        # possible to download the file (or would take an inordinate amount of
        # time), the download process should cap the maximum number of tries
        # to a finite value.
        value = b"Some random string here."

        # The server just gives back the same 4 bytes over and over.
        max_len = _MaxLenFunc(4, 0)

        def _handler(*args):
            return _DroppingHandler(value, max_len, False, *args)

        def _verifier(filelike):
            v = filelike.read() == value
            return v

        with _test_http_server(_handler) as server:
            with self.assertRaises(download.DownloadFailedError):
                with download.get(server.url('/'),
                                  dict(verifier=_verifier, tries=10)) as data:
                    data.read()
Ejemplo n.º 7
0
    def test_download_restart_from_scratch(self):
        # Test that the download function can handle restarting from scratch
        # if the server doesn't support byte range requests.
        value = b"Some random string here."

        # The server initially doesn't give the whole file, but eventually
        # will.
        max_len = _MaxLenFunc(4, 4)

        def _handler(*args):
            return _DroppingHandler(value, max_len, False, *args)

        def _verifier(filelike):
            v = filelike.read() == value
            return v

        with _test_http_server(_handler) as server:
            with download.get(
                    server.url('/'),
                    dict(verifier=_verifier,
                         tries=(old_div(len(value), 4) + 1))) as data:
                self.assertEqual(value, data.read())
Ejemplo n.º 8
0
    def test_download_restart(self):
        # Test that the download function can handle restarting, and fetching
        # a file as a series of smaller byte ranges.
        value = b"Some random string here."

        # The server will only return 4-byte chunks, but it should be possible
        # to download the whole file eventually.
        max_len = _MaxLenFunc(4, 0)

        def _handler(*args):
            return _DroppingHandler(value, max_len, True, *args)

        def _verifier(filelike):
            v = filelike.read() == value
            return v

        with _test_http_server(_handler) as server:
            with download.get(
                    server.url('/'),
                    dict(verifier=_verifier,
                         tries=(old_div(len(value), 4) + 1))) as data:
                self.assertEqual(value, data.read())
Ejemplo n.º 9
0
 def _get(u):
     return stack.enter_context(download.get(u, options))