Exemplo n.º 1
0
    def test_common_link_canceled(self, mock_canceled):
        downloader = local.LocalFileDownloader(DownloaderConfig())
        downloader.cancel()
        request = DownloadRequest('file://' + __file__, '/bar')

        downloader._common_link(mock.MagicMock(), request)

        # make sure the cancel method was called on the report
        mock_canceled.assert_called_once_with()
Exemplo n.º 2
0
    def test_download_method(self):
        # check the default
        config = DownloaderConfig()
        downloader = local.LocalFileDownloader(config)

        self.assertEqual(downloader.download_method, downloader._copy)

        # check configured hard links
        config = DownloaderConfig(use_hard_links=True)
        downloader = local.LocalFileDownloader(config)

        self.assertEqual(downloader.download_method, downloader._hard_link)

        # check configured symbolic links
        config = DownloaderConfig(use_sym_links=True)
        downloader = local.LocalFileDownloader(config)

        self.assertEqual(downloader.download_method, downloader._symbolic_link)
Exemplo n.º 3
0
    def test_copy(self):
        config = DownloaderConfig()
        listener = AggregatingEventListener()
        downloader = local.LocalFileDownloader(config, listener)
        request_list = self._make_requests(DATA_FILES)
        downloader.download(request_list)

        self.assertEqual(len(listener.succeeded_reports), len(request_list))
        self.assertEqual(len(listener.failed_reports), 0)
Exemplo n.º 4
0
    def test_progress_interval(self):
        # check the default
        default_progress_interval = datetime.timedelta(
            seconds=local.DEFAULT_PROGRESS_INTERVAL)
        config = DownloaderConfig()
        downloader = local.LocalFileDownloader(config)

        self.assertFalse(hasattr(downloader, '_progress_interval'))
        self.assertEqual(downloader.progress_interval,
                         default_progress_interval)
        self.assertTrue(hasattr(downloader, '_progress_interval'))

        # check configured value
        ten_second_interval = datetime.timedelta(seconds=10)
        config = DownloaderConfig(progress_interval=10)
        downloader = local.LocalFileDownloader(config)

        self.assertEqual(downloader.progress_interval, ten_second_interval)
Exemplo n.º 5
0
    def test_copy_canceled(self, mock_canceled, mock_open):
        downloader = local.LocalFileDownloader(DownloaderConfig())
        downloader.cancel()
        request = DownloadRequest('file://' + __file__, '/bar')

        downloader._copy(request)

        # make sure the cancel method was called on the report
        mock_canceled.assert_called_once_with()
        # make sure the no writing was attempted
        self.assertEqual(mock_open.return_value.write.call_count, 0)
Exemplo n.º 6
0
    def test_symbolic_link_download(self):
        config = DownloaderConfig(use_sym_links=True)
        listener = AggregatingEventListener()
        downloader = local.LocalFileDownloader(config, listener)
        request_list = self._make_requests(DATA_FILES[:1])
        downloader.download(request_list)

        self.assertEqual(len(listener.succeeded_reports), 1)
        self.assertEqual(len(listener.failed_reports), 0)

        self.assertTrue(os.path.islink(request_list[0].destination))
Exemplo n.º 7
0
    def test_hard_link(self):
        config = DownloaderConfig()
        downloader = local.LocalFileDownloader(config)
        request_list = self._make_requests(DATA_FILES[:1])

        downloader._hard_link(request_list[0])

        src_stat = os.stat(os.path.join(DATA_DIR, DATA_FILES[0]))
        dst_stat = os.stat(request_list[0].destination)

        self.assertEqual(src_stat.st_ino, dst_stat.st_ino)
        self.assertEqual(src_stat.st_nlink, 2)
Exemplo n.º 8
0
    def test_destination_bad_permissions(self):
        config = DownloaderConfig(use_sym_links=True)
        listener = AggregatingEventListener()
        downloader = local.LocalFileDownloader(config, listener)

        request_list = self._make_requests(DATA_DIR[:1])
        request_list[0].destination = '/' + DATA_FILES[0]

        downloader.download(request_list)

        self.assertEqual(len(listener.succeeded_reports), 0)
        self.assertEqual(len(listener.failed_reports), 1)
Exemplo n.º 9
0
    def test_unlinkable_destination(self):
        config = DownloaderConfig(use_hard_links=True)
        listener = AggregatingEventListener()
        downloader = local.LocalFileDownloader(config, listener)

        request_list = self._make_requests(DATA_DIR[:1])
        request_list[0].destination = StringIO()

        downloader.download(request_list)

        self.assertEqual(len(listener.succeeded_reports), 0)
        self.assertEqual(len(listener.failed_reports), 1)
Exemplo n.º 10
0
    def test_source_bad_permissions(self):
        config = DownloaderConfig(use_sym_links=True)
        listener = AggregatingEventListener()
        downloader = local.LocalFileDownloader(config, listener)

        request = DownloadRequest('file://root/no',
                                  os.path.join(self.dest_dir, 'doesnt.even.matter'))

        downloader.download([request])

        self.assertEqual(len(listener.succeeded_reports), 0)
        self.assertEqual(len(listener.failed_reports), 1)
Exemplo n.º 11
0
    def test_unsupported_url_scheme(self):
        config = DownloaderConfig(use_sym_links=True)
        listener = AggregatingEventListener()
        downloader = local.LocalFileDownloader(config, listener)

        request = DownloadRequest('http://thiswontwork.com',
                                  os.path.join(self.dest_dir, 'doesnt.even.matter'))

        downloader.download([request])

        self.assertEqual(len(listener.succeeded_reports), 0)
        self.assertEqual(len(listener.failed_reports), 1)
Exemplo n.º 12
0
    def test_calls_download_method(self):
        config = DownloaderConfig()
        listener = AggregatingEventListener()
        downloader = local.LocalFileDownloader(config, listener)
        request = DownloadRequest('http://foo', StringIO())
        report = DownloadReport.from_download_request(request)

        # mock _copy, which is the default function to which requests are passed
        with mock.patch.object(downloader, '_copy') as mock_method:
            mock_method.return_value = report

            ret = downloader._download_one(request)

            self.assertEqual(ret, report)
            mock_method.assert_called_once_with(request)
Exemplo n.º 13
0
    def test_copy_download(self):
        config = DownloaderConfig()
        listener = AggregatingEventListener()
        downloader = local.LocalFileDownloader(config, listener)
        request_list = self._make_requests(DATA_FILES[:1])
        downloader.download(request_list)

        self.assertEqual(len(listener.succeeded_reports), 1)
        self.assertEqual(len(listener.failed_reports), 0)

        src_stat = os.stat(os.path.join(DATA_DIR, DATA_FILES[0]))
        dst_stat = os.stat(request_list[0].destination)

        self.assertEqual(src_stat.st_size, dst_stat.st_size)
        self.assertNotEqual(src_stat.st_ino, dst_stat.st_ino)
Exemplo n.º 14
0
    def test__common_link_when_source_not_found(self, mock_logger):
        """
        Test that nectar properly handles an attempt to link local files
        that do not exist.
        """
        config = DownloaderConfig(use_sym_links=True)
        listener = AggregatingEventListener()
        downloader = local.LocalFileDownloader(config, listener)

        request = DownloadRequest('file://i/dont/exist',
                                  os.path.join(self.dest_dir, 'doesnt.even.matter'))
        downloader.download([request])

        self.assertEqual(len(listener.succeeded_reports), 0)
        self.assertEqual(len(listener.failed_reports), 1)

        debug_messages = ''.join([mock_call[1][0][1] for mock_call in mock_logger.debug.mock_calls])
        self.assertTrue('No such file or directory' in debug_messages)
        self.assertEqual(mock_logger.exception.call_count, 0)