本文整理汇总了Python中nectar.report.DownloadReport类的典型用法代码示例。如果您正苦于以下问题:Python DownloadReport类的具体用法?Python DownloadReport怎么用?Python DownloadReport使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DownloadReport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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)
示例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)
示例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)
示例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)
示例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')
示例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)
示例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")
示例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
示例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)
示例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)
示例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)
示例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)
示例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')
示例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')