Example #1
0
 def test_download(self):
     """ test the download of a small simple file using download"""
     if os.path.exists(os.path.join(self._results_dir, 'testfile.txt')):
         os.remove(os.path.join(self._results_dir, 'testfile.txt'))
     ftp = FtpFileDownloader(server_url='localhost',
                             username='******',
                             password='******',
                             port=2121,
                             concurrent_connections=4,
                             min_blocks_per_segment=1,
                             max_blocks_per_segment=2,
                             initial_blocksize=1048576,
                             kill_speed=0,
                             clean=False)
     ftp.download('testfile.txt', self._results_dir)
     self.assertTrue(
         filecmp.cmp(os.path.join(self._test_dir, 'testfile.txt'),
                     os.path.join(self._results_dir, 'testfile.txt'),
                     shallow=False))
Example #2
0
 def test_broken_tls(self):
     """ test correct response if server does not support tls """
     if os.path.exists(os.path.join(self._results_dir, 'testfile.txt')):
         os.remove(os.path.join(self._results_dir, 'testfile.txt'))
     ftp = FtpFileDownloader(server_url='localhost',
                             username='******',
                             password='******',
                             port=2121,
                             concurrent_connections=4,
                             min_blocks_per_segment=1,
                             max_blocks_per_segment=2,
                             initial_blocksize=1048576,
                             kill_speed=0,
                             clean=False,
                             enable_tls=True)
     try:
         ftp.download('testfile.txt', self._results_dir)
     except ftplib.error_perm as e:
         self.assertEqual(str(e), '500 Command "AUTH" not understood.')
Example #3
0
    def test_resume_aborted_download2(self):
        """ test the handling of resuming a previously aborted download with a blocksize change"""
        self._blocks_downloaded = 0

        def on_refresh_display(ftp_download_manager, blockmap,
                               _remote_filepath):
            """ on refresh display handler """
            self._blocks_downloaded = self._blocks_downloaded + 1
            # make sure statistics do not crash
            blockmap.get_statistics()
            if self._blocks_downloaded > 2:
                ftp_download_manager.abort_download()

        # abort the download after 2 blocks have been downloaded with a blocksize of 65536
        ftp = FtpFileDownloader(server_url='localhost',
                                username='******',
                                password='******',
                                port=2121,
                                concurrent_connections=4,
                                min_blocks_per_segment=1,
                                max_blocks_per_segment=2,
                                initial_blocksize=65536,
                                kill_speed=0,
                                clean=True)
        ftp.on_refresh_display = on_refresh_display
        ftp.download('testfile.txt', self._results_dir)
        self.assertFalse(
            filecmp.cmp(os.path.join(self._test_dir, 'testfile.txt'),
                        os.path.join(self._results_dir, 'testfile.txt'),
                        shallow=False))

        # resume the download
        ftp = FtpFileDownloader(server_url='localhost',
                                username='******',
                                password='******',
                                port=2121,
                                concurrent_connections=4,
                                min_blocks_per_segment=1,
                                max_blocks_per_segment=2,
                                initial_blocksize=1048576,
                                kill_speed=0,
                                clean=False)
        ftp.download('testfile.txt', self._results_dir)
        self.assertTrue(
            filecmp.cmp(os.path.join(self._test_dir, 'testfile.txt'),
                        os.path.join(self._results_dir, 'testfile.txt'),
                        shallow=False))
    def test_directory_download(self):
        """ test the download of a directory using download_file """
        # clean up the results directory
        dir_path = os.path.join(self._results_dir, 'dir_test')
        if os.path.exists(dir_path):
            shutil.rmtree(dir_path)

        # download the directory
        ftp = FtpFileDownloader(server_url='localhost', username='******', password='******', port=2121,
                                concurrent_connections=4, min_blocks_per_segment=1, max_blocks_per_segment=2,
                                initial_blocksize=1048576, kill_speed=0, clean=True)
        ftp.download('/', dir_path)

        # verify the sub directory was actually created
        self.assertTrue(os.path.exists(os.path.join(dir_path, 'a')))
        self.assertFalse(os.path.isfile(os.path.join(dir_path, 'a')))

        # verify the files were downloaded correctly
        self.assertTrue(filecmp.cmp(os.path.join(self._test_dir, 'testfile.txt'),
                                    os.path.join(dir_path, 'testfile.txt'), shallow=False))
        self.assertTrue(filecmp.cmp(os.path.join(self._test_dir, 'a/testfile2.txt'),
                                    os.path.join(dir_path, 'a/testfile2.txt'), shallow=False))
Example #5
0
    def test_pretty_summary_line(self):
        """ test pretty summary line function """
        ftp = FtpFileDownloader(server_url='localhost',
                                username='******',
                                password='******',
                                port=2121,
                                concurrent_connections=4,
                                min_blocks_per_segment=1,
                                max_blocks_per_segment=2,
                                initial_blocksize=1048576,
                                kill_speed=0,
                                clean=True)

        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 32)
        blockmap.init_blockmap()

        s = superftp._pretty_summary_line(ftp, blockmap, '\remote\test')
        self.assertEqual(
            s, 'ETA:infinite        0.0%  0.000MB/sec  \remote\test')
Example #6
0
    def test_display_full(self):
        """ test _display_compact function """
        # create a FtpFileDownloader for the test
        ftp = FtpFileDownloader(server_url='localhost',
                                username='******',
                                password='******',
                                port=2121,
                                concurrent_connections=4,
                                min_blocks_per_segment=1,
                                max_blocks_per_segment=2,
                                initial_blocksize=1048576,
                                kill_speed=0,
                                clean=True)

        # create a blockmap for the test
        blockmap = create_blockmap(self._results_dir, 1024 * 1024 * 32)
        blockmap.init_blockmap()
        blockmap.change_block_range_status(1024 * 1024 * 2, 2,
                                           Blockmap.DOWNLOADED)
        blockmap.change_block_range_status(1024 * 1024 * 24, 2,
                                           Blockmap.PENDING)
        blockmap.change_block_range_status(1024 * 1024 * 30, 2,
                                           Blockmap.SAVING)

        # check the display_compact
        with captured_output() as (out, err):
            superftp._display_full(ftp, blockmap, '\remote\test', (24, 80))
        s = err.getvalue()
        self.assertEqual(s, '')
        s = out.getvalue()
        truth = (
            '\x1b[1;0H\x1b[37mETA:infinite        3.2%  0.000MB/sec  \remote\test\x1b[K\x1b[2;0H\x1b[K\x1b[3;0H'
            +
            '\x1b[37m[0.000][0.000][0.000][0.000]\x1b[K\n[0.000][0.000][0.000][0.000]\x1b[K\n[0.000][0.000]'
            +
            '[0.000][0.000]\x1b[K\n[0.000][0.000][0.000][0.000]\x1b[K\n\x1b[7;0H\x1b[K\x1b[8;0H\x1b[37m..\x1b'
            +
            '[92m**\x1b[37m....................\x1b[93m001234__789ABCDEF23456789ABCDEF\x1b[37m.......\x1b[K\r\n'
            +
            '\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r'
            + '\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[K\r\n\x1b[J')
        self.assertEqual(s, truth)