本文整理汇总了Python中pulp_puppet.plugins.importers.directory.SynchronizeWithDirectory._download方法的典型用法代码示例。如果您正苦于以下问题:Python SynchronizeWithDirectory._download方法的具体用法?Python SynchronizeWithDirectory._download怎么用?Python SynchronizeWithDirectory._download使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp_puppet.plugins.importers.directory.SynchronizeWithDirectory
的用法示例。
在下文中一共展示了SynchronizeWithDirectory._download方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_download
# 需要导入模块: from pulp_puppet.plugins.importers.directory import SynchronizeWithDirectory [as 别名]
# 或者: from pulp_puppet.plugins.importers.directory.SynchronizeWithDirectory import _download [as 别名]
def test_download(self, mock_listener, mock_nectar_config, mock_downloader_mapping):
mock_nectar_config.return_value = Mock()
mock_http_downloader = Mock()
mock_http_class = Mock(return_value=mock_http_downloader)
mock_downloader_mapping.__getitem__.return_value = mock_http_class
mock_repo = Mock()
conduit = Mock()
config = Mock()
config.get = Mock(side_effect={constants.CONFIG_FEED: 'http://host/root/PULP_MANAFEST'})
config.flatten = Mock(return_value={})
urls = [
('http://host/root/path_1', '/tmp/path_1'),
('http://host/root/path_2', '/tmp/path_1'),
]
report = namedtuple('Report', ['url', 'destination', 'error_msg'])
_listener = Mock()
_listener.succeeded_reports = [report(urls[0][0], urls[0][1], None)]
_listener.failed_reports = [report(urls[1][0], urls[1][1], 'File Not Found')]
mock_listener.return_value = _listener
# test
method = SynchronizeWithDirectory(mock_repo, conduit, config)
succeeded_reports, failed_reports = method._download(urls)
# validation
method.config.flatten.assert_called_with()
mock_nectar_config.assert_called_with(method.config.flatten())
self.assertTrue(mock_http_downloader.download.called)
self.assertEqual(mock_http_downloader.download.call_count, 1)
self.assertEqual(mock_http_downloader.download.call_args[0][0][0].url, urls[0][0])
self.assertEqual(mock_http_downloader.download.call_args[0][0][0].destination, urls[0][1])
self.assertEqual(mock_http_downloader.download.call_args[0][0][1].url, urls[1][0])
self.assertEqual(mock_http_downloader.download.call_args[0][0][0].destination, urls[1][1])
self.assertTrue(isinstance(succeeded_reports, list))
self.assertEqual(len(succeeded_reports), 1)
self.assertEqual(succeeded_reports[0].url, urls[0][0])
self.assertEqual(succeeded_reports[0].destination, urls[0][1])
self.assertTrue(isinstance(succeeded_reports, list))
self.assertTrue(isinstance(failed_reports, list))
self.assertEqual(len(failed_reports), 1)
self.assertEqual(failed_reports[0].url, urls[1][0])
self.assertEqual(failed_reports[0].destination, urls[1][1])
self.assertTrue(isinstance(failed_reports, list))