• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python report.DownloadReport类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nectar.report.DownloadReport的典型用法代码示例。如果您正苦于以下问题:Python DownloadReport类的具体用法?Python DownloadReport怎么用?Python DownloadReport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DownloadReport类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_download_failed

    def test_download_failed(self):
        report = DownloadReport('', '')
        report.error_report['response_code'] = 1234

        # test
        listener = DownloadListener(None, None)
        listener.download_failed(report)
开发者ID:release-engineering,项目名称:pulp,代码行数:7,代码来源:test_server.py


示例2: test_download_succeeded

    def test_download_succeeded(self, download_failed):
        destination = os.path.join(self.temp_dir, 'test.txt')
        with open(destination, 'w') as test_file:
            test_file.write(
                'Descartes walks into a bar and sits down, the bartender walks up to him and says '
                '"You, my '
                'man, look like you need a stiff drink." Descartes considers this, and shakes his '
                'head "No, '
                'I don\'t think-" and ceases to exist.')
        unit = MagicMock()
        unit.storage_path = destination
        iso = models.ISO('test.txt', 217,
                         'a1552efee6f04012bc7e1f3e02c00c6177b08217cead958c47ec83cb8f97f835',
                         unit)
        iso.url = 'http://fake.com'
        report = DownloadReport(iso.url, destination, iso)

        # Simulate having downloaded the whole file
        iso.bytes_downloaded = iso.size
        report.bytes_downloaded = iso.size
        self.iso_sync_run.progress_report._state = SyncProgressReport.STATE_ISOS_IN_PROGRESS

        self.iso_sync_run.download_succeeded(report)

        # The sync conduit should have been called to save the unit
        self.sync_conduit.save_unit.assert_any_call(unit)
        # The download should not fail
        self.assertEqual(download_failed.call_count, 0)
开发者ID:hjensas,项目名称:pulp_rpm,代码行数:28,代码来源:test_sync.py


示例3: test_download_succeeded_fails_checksum

    def test_download_succeeded_fails_checksum(self, download_failed):
        """
        This test verifies that download_succeeded does the right thing if the checksum fails. Note
        that we are also implicitly testing that the default behavior is to validate downloads by
        not setting it in this test. There are two other tests that verify that setting the boolean
        explicitly is honored.
        """
        self.config.override_config[importer_constants.KEY_VALIDATE] = True

        iso_sync_run = ISOSyncRun(self.sync_conduit, self.config)

        destination = os.path.join(self.temp_dir, 'test.txt')
        with open(destination, 'w') as test_file:
            test_file.write('Boring test data.')
        unit = MagicMock()
        unit.storage_path = destination
        iso = models.ISO('test.txt', 114, 'wrong checksum', unit)
        iso.url = 'http://fake.com'
        report = DownloadReport(iso.url, destination, iso)

        # Let's fake having downloaded the whole file
        iso.bytes_downloaded = iso.size
        report.bytes_downloaded = iso.size
        iso_sync_run.progress_report._state = SyncProgressReport.STATE_ISOS_IN_PROGRESS

        iso_sync_run.download_succeeded(report)

        # Because we fail validation, the save_unit step will not be called
        self.assertEqual(self.sync_conduit.save_unit.call_count, 0)
        # The download should be marked failed
        self.assertEqual(download_failed.call_count, 1)
        download_failed.assert_called_once_with(report)
开发者ID:hjensas,项目名称:pulp_rpm,代码行数:32,代码来源:test_sync.py


示例4: test_download_succeeded_honors_validate_units_set_false

    def test_download_succeeded_honors_validate_units_set_false(self, download_failed):
        """
        We have a setting that makes download validation optional. This test ensures that download_succeeded()
        honors that setting.
        """
        # In this config, we will set validate_units to False, which should make our "wrong_checksum" OK
        config = importer_mocks.get_basic_config(**{importer_constants.KEY_FEED: 'http://fake.com/iso_feed/',
                                                    importer_constants.KEY_VALIDATE: False})

        iso_sync_run = ISOSyncRun(self.sync_conduit, config)

        destination = os.path.join(self.temp_dir, 'test.iso')
        with open(destination, 'w') as test_iso:
            test_iso.write('What happens when you combine a mosquito with a mountain climber? Nothing. You '
                           'can\'t cross a vector with a scalar.')
        unit = MagicMock()
        unit.storage_path = destination
        iso = models.ISO('test.txt', 114, 'wrong checksum', unit)
        iso.url = 'http://fake.com'
        report = DownloadReport(iso.url, destination, iso)

        # Let's fake having downloaded the whole file
        iso.bytes_downloaded = iso.size
        report.bytes_downloaded = iso.size
        iso_sync_run.progress_report._state = SyncProgressReport.STATE_ISOS_IN_PROGRESS

        iso_sync_run.download_succeeded(report)

        # The sync conduit should have been called to save the unit
        self.sync_conduit.save_unit.assert_any_call(unit)
        # The download should not fail
        self.assertEqual(download_failed.call_count, 0)
开发者ID:bechtoldt,项目名称:pulp_rpm,代码行数:32,代码来源:test_iso_importer_sync.py


示例5: test_download_succeeded_honors_validate_units_set_true

    def test_download_succeeded_honors_validate_units_set_true(self, download_failed):
        """
        We have a setting that makes download validation optional. This test ensures that
        download_succeeded()
        honors that setting.
        """
        # In this config, we will set validate_units to False, which should make our
        # "wrong_checksum" OK
        config = importer_mocks.get_basic_config(
            **{importer_constants.KEY_FEED: 'http://fake.com/iso_feed/',
               importer_constants.KEY_VALIDATE: True})

        iso_sync_run = ISOSyncRun(self.sync_conduit, config)

        destination = os.path.join(self.temp_dir, 'test.txt')
        with open(destination, 'w') as test_file:
            test_file.write('Boring test data.')
        unit = MagicMock()
        unit.storage_path = destination
        iso = models.ISO('test.txt', 114, 'wrong checksum', unit)
        iso.url = 'http://fake.com'
        report = DownloadReport(iso.url, destination, iso)

        # Let's fake having downloaded the whole file
        iso.bytes_downloaded = iso.size
        report.bytes_downloaded = iso.size
        iso_sync_run.progress_report._state = SyncProgressReport.STATE_ISOS_IN_PROGRESS

        iso_sync_run.download_succeeded(report)

        # Because we fail validation, the save_unit step will not be called
        self.assertEqual(self.sync_conduit.save_unit.call_count, 0)
        # The download should be marked failed
        self.assertEqual(download_failed.call_count, 1)
        download_failed.assert_called_once_with(report)
开发者ID:hjensas,项目名称:pulp_rpm,代码行数:35,代码来源:test_sync.py


示例6: test_get_single_path_failure

    def test_get_single_path_failure(self, mock_download_one):
        report = DownloadReport('http://pulpproject.org/v1/repositories/pulp/crane/images',
                                StringIO(''))
        report.headers = {}
        report.state = report.DOWNLOAD_FAILED
        mock_download_one.return_value = report

        self.assertRaises(IOError, self.repo._get_single_path, '/v1/repositories/pulp/crane/images')
开发者ID:TomasTomecek,项目名称:pulp_docker,代码行数:8,代码来源:test_registry.py


示例7: download_failed

 def download_failed(self, request):
     """
     Notification that downloading has failed for the specified request.
     Fields mapped and forwarded to the wrapped listener.
     :param request: A download request.
     :type request: pulp.server.content.sources.model.Request
     """
     report = DownloadReport(request.url, request.destination, request.data)
     report.error_report['errors'] = request.errors
     self.content_listener.download_failed(report)
开发者ID:AndreaGiardini,项目名称:pulp_rpm,代码行数:10,代码来源:alternate.py


示例8: TestDownloadReport

class TestDownloadReport(unittest.TestCase):

    def setUp(self):
        self.report = DownloadReport("fakeurl", "fakedestination")

    def test_download_connection_error(self):

        self.report.download_connection_error()
        self.assertEqual(self.report.state, self.report.DOWNLOAD_FAILED)
        self.assertEqual(self.report.error_msg, "A connection error occurred")
开发者ID:osabina,项目名称:nectar,代码行数:10,代码来源:test_base_downloader.py


示例9: download_one

 def download_one(request):
     """
     Mock the download_one() method to manipulate the path.
     """
     self.assertEqual(request.url, 'https://registry.example.com/v2/')
     self.assertEqual(type(request.destination), type(StringIO()))
     report = DownloadReport(request.url, request.destination)
     report.download_succeeded()
     report.headers = {'Docker-Distribution-API-Version': 'registry/2.0'}
     report.destination.write("")
     return report
开发者ID:shubham90,项目名称:pulp_docker,代码行数:11,代码来源:test_registry.py


示例10: test__raise_path_error_not_found

    def test__raise_path_error_not_found(self):
        """
        For a standard error like 404, the report's error message should be used.
        """
        report = DownloadReport('http://foo/bar', '/a/b/c')
        report.error_report = {'response_code': httplib.NOT_FOUND}
        report.error_msg = 'oops'

        with self.assertRaises(IOError) as assertion:
            registry.V2Repository._raise_path_error(report)

        self.assertEqual(assertion.exception.message, report.error_msg)
开发者ID:daviddavis,项目名称:pulp_docker,代码行数:12,代码来源:test_registry.py


示例11: test_download_failed_during_manifest

    def test_download_failed_during_manifest(self):
        self.iso_sync_run.progress_report._state = SyncProgressReport.STATE_MANIFEST_IN_PROGRESS
        url = 'http://www.theonion.com/articles/' +\
            'american-airlines-us-airways-merge-to-form-worlds,31302/'
        report = DownloadReport(url, '/fake/destination')
        report.error_report = {'why': 'because'}

        self.iso_sync_run.download_failed(report)

        # The manifest_state should be failed
        self.assertEqual(self.iso_sync_run.progress_report._state,
                         SyncProgressReport.STATE_MANIFEST_FAILED)
        self.assertEqual(self.iso_sync_run.progress_report.error_message, report.error_report)
开发者ID:bechtoldt,项目名称:pulp_rpm,代码行数:13,代码来源:test_iso_importer_sync.py


示例12: test_download_failed_during_iso_download

    def test_download_failed_during_iso_download(self, _logger):
        self.iso_sync_run.progress_report._state = SyncProgressReport.STATE_ISOS_IN_PROGRESS
        url = 'http://www.theonion.com/articles/american-airlines-us-airways-merge-to-form' \
              '-worlds,31302/'
        iso = models.ISO('test.txt', 217,
                         'a1552efee6f04012bc7e1f3e02c00c6177b08217cead958c47ec83cb8f97f835')
        report = DownloadReport(url, '/fake/destination', iso)
        report.error_msg = 'uh oh'

        self.iso_sync_run.download_failed(report)

        self.assertEqual(_logger.error.call_count, 1)
        log_msg = _logger.error.mock_calls[0][1][0]
        self.assertTrue('uh oh' in log_msg)
开发者ID:hjensas,项目名称:pulp_rpm,代码行数:14,代码来源:test_sync.py


示例13: test_failed_reports

    def test_failed_reports(self):
        self.metadata_files.downloader.download = mock.MagicMock(
            spec_set=self.metadata_files.downloader.download
        )
        self.metadata_files.metadata = {
            'primary': file_info_factory('primary'),
        }

        report = DownloadReport('url', '/destination')
        report.download_failed()
        self.metadata_files.event_listener.failed_reports.append(report)

        # Ensure an exception is raised if the download failed
        self.assertRaises(IOError, self.metadata_files.download_metadata_files)
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:14,代码来源:test_metadata.py


示例14: test_get_tags

    def test_get_tags(self, mock_download_one):
        body = json.dumps({'latest': 'abc123'})
        report = DownloadReport('http://pulpproject.org/v1/repositories/pulp/crane/tags',
                                StringIO(body))
        report.headers = {}
        mock_download_one.return_value = report

        ret = self.repo._get_single_path('/v1/repositories/pulp/crane/tags')

        self.assertEqual(ret, {'latest': 'abc123'})
        self.assertEqual(mock_download_one.call_count, 1)
        self.assertTrue(isinstance(mock_download_one.call_args[0][0], DownloadRequest))
        req = mock_download_one.call_args[0][0]
        self.assertEqual(req.url, 'http://pulpproject.org/v1/repositories/pulp/crane/tags')
开发者ID:TomasTomecek,项目名称:pulp_docker,代码行数:14,代码来源:test_registry.py


示例15: test_get_with_headers

    def test_get_with_headers(self, mock_download_one):
        body = json.dumps(['abc123'])
        report = DownloadReport('http://pulpproject.org/v1/repositories/pulp/crane/images',
                                StringIO(body))
        report.headers = {
            self.repo.DOCKER_TOKEN_HEADER: 'token',
            self.repo.DOCKER_ENDPOINT_HEADER: 'endpoint',
        }
        mock_download_one.return_value = report

        self.repo._get_single_path('/v1/repositories/pulp/crane/images')

        self.assertEqual(self.repo.token, 'token')
        self.assertEqual(self.repo.endpoint, 'endpoint')
开发者ID:TomasTomecek,项目名称:pulp_docker,代码行数:14,代码来源:test_registry.py


示例16: test_retrieve_metadata_with_error

    def test_retrieve_metadata_with_error(self, mock_downloader_download, mock_listener_constructor):
        # Setup
        mock_listener = mock.MagicMock()
        report = DownloadReport(None, None)
        report.error_msg = 'oops'
        mock_listener.failed_reports = [report]
        mock_listener_constructor.return_value = mock_listener

        # Test
        try:
            self.downloader.retrieve_metadata(self.mock_progress_report)
            self.fail()
        except exceptions.FileRetrievalException:
            pass
开发者ID:asmacdo,项目名称:pulp_puppet,代码行数:14,代码来源:test_web.py


示例17: _common_link

    def _common_link(self, link_method, request, report=None):
        """
        Link files using either a hard link or symbolic link method.

        :param link_method: hard link or symbolic link method
        :type link_method: callable
        :param request: request instance
        :type request: nectar.request.DownloadRequest
        :param report: report instance for the request
        :type report: nectar.report.DownloadReport
        :return: report instance
        :rtype: nectar.report.DownloadReport
        """

        report = report or DownloadReport.from_download_request(request)

        report.download_started()
        self.fire_download_started(report)

        if self.is_canceled:
            report.download_cancelled()
            return report

        try:
            if not isinstance(request.destination, basestring):
                raise UnlinkableDestination(request.destination)

            src_path = self._file_path_from_url(request.url)
            link_method(src_path, request.destination)

        except Exception, e:
            _LOG.exception(e)
            report.error_msg = str(e)
            report.download_failed()
开发者ID:dhajoshi,项目名称:nectar,代码行数:34,代码来源:local.py


示例18: drain

 def drain(self):
     """
     Read and fail all requests remaining in the queue.
     """
     for request in NectarFeed(self):
         report = NectarDownloadReport.from_download_request(request)
         self.downloader.fire_download_failed(report)
开发者ID:AndreaGiardini,项目名称:pulp,代码行数:7,代码来源:container.py


示例19: test_retrieve_module_missing_module

    def test_retrieve_module_missing_module(self, mock_downloader_download, mock_listener_constructor):
        # Setup
        mock_listener = mock.MagicMock()
        report = DownloadReport(None, None)
        report.error_msg = 'oops'
        mock_listener.failed_reports = [report]
        mock_listener_constructor.return_value = mock_listener

        # Test
        try:
            self.downloader.retrieve_module(self.mock_progress_report, self.module)
            self.fail()
        except exceptions.FileRetrievalException:
            expected_filename = web._create_download_tmp_dir(self.working_dir)
            expected_filename = os.path.join(expected_filename, self.module.filename())
            self.assertFalse(os.path.exists(os.path.join(expected_filename)))
开发者ID:asmacdo,项目名称:pulp_puppet,代码行数:16,代码来源:test_web.py


示例20: test_get_images

    def test_get_images(self, mock_download_one):
        body = json.dumps(['abc123'])
        report = DownloadReport('http://pulpproject.org/v1/repositories/pulp/crane/images',
                                StringIO(body))
        report.headers = {}
        mock_download_one.return_value = report

        ret = self.repo._get_single_path('/v1/repositories/pulp/crane/images')

        self.assertEqual(ret, ['abc123'])
        self.assertEqual(mock_download_one.call_count, 1)
        self.assertTrue(isinstance(mock_download_one.call_args[0][0], DownloadRequest))
        req = mock_download_one.call_args[0][0]
        self.assertEqual(req.url, 'http://pulpproject.org/v1/repositories/pulp/crane/images')
        # make sure this header is set, which is required by the docker API in order
        # to give us an auth token
        self.assertEqual(req.headers[self.repo.DOCKER_TOKEN_HEADER], 'true')
开发者ID:TomasTomecek,项目名称:pulp_docker,代码行数:17,代码来源:test_registry.py



注:本文中的nectar.report.DownloadReport类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python allocation.AllocationRequest类代码示例发布时间:2022-05-27
下一篇:
Python threaded.HTTPThreadedDownloader类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap