本文整理汇总了Python中pulp_puppet.plugins.importers.directory.SynchronizeWithDirectory._extract_metadata方法的典型用法代码示例。如果您正苦于以下问题:Python SynchronizeWithDirectory._extract_metadata方法的具体用法?Python SynchronizeWithDirectory._extract_metadata怎么用?Python SynchronizeWithDirectory._extract_metadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp_puppet.plugins.importers.directory.SynchronizeWithDirectory
的用法示例。
在下文中一共展示了SynchronizeWithDirectory._extract_metadata方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_import_modules_failed
# 需要导入模块: from pulp_puppet.plugins.importers.directory import SynchronizeWithDirectory [as 别名]
# 或者: from pulp_puppet.plugins.importers.directory.SynchronizeWithDirectory import _extract_metadata [as 别名]
def test_import_modules_failed(self):
"""
Test that when there was some failure in a previous step, _import_modules does not
overwrite the failed state
"""
config = {}
mock_conduit = Mock()
mock_inventory = Mock()
method = SynchronizeWithDirectory(mock_conduit, config)
method.started_fetch_modules = 0
method._extract_metadata = Mock(return_value={'name': 'j-p', 'author': 'J', 'version': '1.1'})
method.report = Mock()
method.report.modules_total_count = 1
method.report.modules_finished_count = 0
method.report.modules_state = constants.STATE_FAILED
# test
imported_modules = method._import_modules(mock_inventory, ['/path1'])
# validation
self.assertEquals(constants.STATE_FAILED, method.report.modules_state)
self.assertEquals(1, method.report.update_progress.call_count)
self.assertEquals(0, method.report.modules_total_count)
self.assertEquals(0, method.report.modules_finished_count)
self.assertEquals([], imported_modules)
示例2: test_extract_metadata
# 需要导入模块: from pulp_puppet.plugins.importers.directory import SynchronizeWithDirectory [as 别名]
# 或者: from pulp_puppet.plugins.importers.directory.SynchronizeWithDirectory import _extract_metadata [as 别名]
def test_extract_metadata(self, *mocks):
mock_mkdtemp, mock_tarfile, mock_json, mock_shutil, mock_open = mocks
Member = namedtuple('Member', ['name'])
module_path = '/build/modules/puppet-module.tar.gz'
mock_mkdtemp.return_value = '/tmp/xx'
members = [
Member(name='puppet-module'),
Member(name='puppet-module/manifests'),
Member(name='puppet-module/spec'),
Member(name='puppet-module/templates'),
Member(name='puppet-module/tests'),
Member(name='puppet-module/CHANGELOG'),
Member(name='puppet-module/%s' % constants.MODULE_METADATA_FILENAME),
Member(name='puppet-module/README'),
]
tarball = Mock()
tarball.getmembers = Mock(return_value=members)
mock_tarfile.open = Mock(return_value=tarball)
mock_fp = Mock()
mock_fp.__enter__ = Mock(return_value=mock_fp)
mock_fp.__exit__ = Mock()
mock_open.return_value = mock_fp
mock_json.load.return_value = '12345'
# test
SynchronizeWithDirectory._extract_metadata(module_path)
# validation
mock_mkdtemp.assert_called_with(dir=os.path.dirname(module_path))
mock_tarfile.open.assert_called_with(module_path)
tarball.getmembers.assert_called_with()
tarball.extract.assert_called_with(members[6], mock_mkdtemp())
mock_open.assert_called_with(os.path.join(mock_mkdtemp(), members[6].name))
mock_json.load.assert_called_with(mock_fp)
mock_shutil.rmtree.assert_called_with(mock_mkdtemp())