本文整理汇总了Python中nectar.report.DownloadReport.bytes_downloaded方法的典型用法代码示例。如果您正苦于以下问题:Python DownloadReport.bytes_downloaded方法的具体用法?Python DownloadReport.bytes_downloaded怎么用?Python DownloadReport.bytes_downloaded使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nectar.report.DownloadReport
的用法示例。
在下文中一共展示了DownloadReport.bytes_downloaded方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_download_succeeded_fails_checksum
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import bytes_downloaded [as 别名]
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)
示例2: test_download_succeeded
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import bytes_downloaded [as 别名]
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_honors_validate_units_set_true
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import bytes_downloaded [as 别名]
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)
示例4: test_download_succeeded_honors_validate_units_set_false
# 需要导入模块: from nectar.report import DownloadReport [as 别名]
# 或者: from nectar.report.DownloadReport import bytes_downloaded [as 别名]
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)