本文整理汇总了Python中pulp.plugins.model.Unit.id方法的典型用法代码示例。如果您正苦于以下问题:Python Unit.id方法的具体用法?Python Unit.id怎么用?Python Unit.id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp.plugins.model.Unit
的用法示例。
在下文中一共展示了Unit.id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: to_plugin_unit
# 需要导入模块: from pulp.plugins.model import Unit [as 别名]
# 或者: from pulp.plugins.model.Unit import id [as 别名]
def to_plugin_unit(pulp_unit, type_def):
"""
Parses the raw dictionary of a content unit into its plugin representation.
@param pulp_unit: raw dictionary of unit metadata
@type pulp_unit: dict
@param type_def: Pulp stored definition for the unit type
@type type_def: pulp.server.db.model.content.ContentType
@return: plugin unit representation of the given unit
@rtype: pulp.plugins.model.Unit
"""
# Copy so we don't mangle the original unit
pulp_unit = dict(pulp_unit)
key_list = type_def['unit_key']
unit_key = {}
for k in key_list:
unit_key[k] = pulp_unit.pop(k)
storage_path = pulp_unit.pop('_storage_path', None)
unit_id = pulp_unit.pop('_id', None)
u = Unit(type_def['id'], unit_key, pulp_unit, storage_path)
u.id = unit_id
return u
示例2: test_link_unit
# 需要导入模块: from pulp.plugins.model import Unit [as 别名]
# 或者: from pulp.plugins.model.Unit import id [as 别名]
def test_link_unit(self, mock_link):
# Setup
from_unit = Unit('t1', {'k' : 'v1'}, {'m' : 'm'}, 'p')
from_unit.id = 'from-unit'
to_unit = Unit('t2', {'k' : 'v2'}, {'m' : 'm'}, 'p')
to_unit.id = 'to-unit'
# Test
self.mixin.link_unit(from_unit, to_unit)
# Verify
self.assertEqual(1, mock_link.call_count)
self.assertEqual(mock_link.call_args[0][0], from_unit.type_id)
self.assertEqual(mock_link.call_args[0][1], from_unit.id)
self.assertEqual(mock_link.call_args[0][2], to_unit.type_id)
self.assertEqual(mock_link.call_args[0][3], [to_unit.id])
示例3: test_handle_erratum_with_link
# 需要导入模块: from pulp.plugins.model import Unit [as 别名]
# 或者: from pulp.plugins.model.Unit import id [as 别名]
def test_handle_erratum_with_link(self, mock_link):
# Setup
unit_key = {'id': 'test-erratum'}
metadata = {'a': 'a'}
config = PluginCallConfiguration({}, {})
mock_repo = mock.MagicMock()
mock_conduit = mock.MagicMock()
inited_unit = Unit(models.Errata.TYPE, unit_key, metadata, None)
saved_unit = Unit(models.Errata.TYPE, unit_key, metadata, None)
saved_unit.id = 'ihaveanidnow'
mock_conduit.init_unit.return_value = inited_unit
mock_conduit.save_unit.return_value = saved_unit
# Test
upload._handle_erratum(mock_repo, models.Errata.TYPE, unit_key, metadata, None,
mock_conduit, config)
# Verify
mock_conduit.init_unit.assert_called_once_with(models.Errata.TYPE, unit_key,
metadata, None)
mock_conduit.save_unit.assert_called_once_with(inited_unit)
mock_link.assert_called_once()
self.assertEqual(mock_link.call_args[0][0], mock_conduit)
self.assertTrue(isinstance(mock_link.call_args[0][1], models.Errata))
# it is very important that this is the saved_unit, and not the inited_unit,
# because the underlying link logic requires it to have an "id".
self.assertTrue(mock_link.call_args[0][2] is saved_unit)
示例4: to_plugin_unit
# 需要导入模块: from pulp.plugins.model import Unit [as 别名]
# 或者: from pulp.plugins.model.Unit import id [as 别名]
def to_plugin_unit(pulp_unit, unit_type_id, unit_key_fields):
"""
Parses the raw dictionary of a content unit into its plugin representation.
:param pulp_unit: raw dictionary of unit metadata
:type pulp_unit: dict
:param unit_type_id: unique identifier for the type of unit
:type unit_type_id: str
:param unit_key_fields: collection of keys required for the type's unit key
:type unit_key_fields: list or tuple
:return: plugin unit representation of the given unit
:rtype: pulp.plugins.model.Unit
"""
# Copy so we don't mangle the original unit
pulp_unit = dict(pulp_unit)
unit_key = {}
for k in unit_key_fields:
unit_key[k] = pulp_unit.pop(k)
storage_path = pulp_unit.pop('_storage_path', None)
unit_id = pulp_unit.pop('_id', None)
u = Unit(unit_type_id, unit_key, pulp_unit, storage_path)
u.id = unit_id
return u
示例5: test_link_unit
# 需要导入模块: from pulp.plugins.model import Unit [as 别名]
# 或者: from pulp.plugins.model.Unit import id [as 别名]
def test_link_unit(self, mock_link):
# Setup
from_unit = Unit("t1", {"k": "v1"}, {"m": "m"}, "p")
from_unit.id = "from-unit"
to_unit = Unit("t2", {"k": "v2"}, {"m": "m"}, "p")
to_unit.id = "to-unit"
# Test
self.mixin.link_unit(from_unit, to_unit)
# Verify
self.assertEqual(1, mock_link.call_count)
self.assertEqual(mock_link.call_args[0][0], from_unit.type_id)
self.assertEqual(mock_link.call_args[0][1], from_unit.id)
self.assertEqual(mock_link.call_args[0][2], to_unit.type_id)
self.assertEqual(mock_link.call_args[0][3], [to_unit.id])
示例6: test_link_unit_bidirectional
# 需要导入模块: from pulp.plugins.model import Unit [as 别名]
# 或者: from pulp.plugins.model.Unit import id [as 别名]
def test_link_unit_bidirectional(self, mock_link):
# Setup
from_unit = Unit('t1', {'k' : 'v1'}, {'m' : 'm'}, 'p')
from_unit.id = 'from-unit'
to_unit = Unit('t2', {'k' : 'v2'}, {'m' : 'm'}, 'p')
to_unit.id = 'to-unit'
# Test
self.mixin.link_unit(from_unit, to_unit, bidirectional=True)
# Verify
self.assertEqual(2, mock_link.call_count)
call_1_args = mock_link.call_args_list[0][0]
self.assertEqual(call_1_args[0], from_unit.type_id)
self.assertEqual(call_1_args[1], from_unit.id)
self.assertEqual(call_1_args[2], to_unit.type_id)
self.assertEqual(call_1_args[3], [to_unit.id])
call_2_args = mock_link.call_args_list[1][0]
self.assertEqual(call_2_args[0], to_unit.type_id)
self.assertEqual(call_2_args[1], to_unit.id)
self.assertEqual(call_2_args[2], from_unit.type_id)
self.assertEqual(call_2_args[3], [from_unit.id])
示例7: test_link_unit_bidirectional
# 需要导入模块: from pulp.plugins.model import Unit [as 别名]
# 或者: from pulp.plugins.model.Unit import id [as 别名]
def test_link_unit_bidirectional(self, mock_link):
# Setup
from_unit = Unit("t1", {"k": "v1"}, {"m": "m"}, "p")
from_unit.id = "from-unit"
to_unit = Unit("t2", {"k": "v2"}, {"m": "m"}, "p")
to_unit.id = "to-unit"
# Test
self.mixin.link_unit(from_unit, to_unit, bidirectional=True)
# Verify
self.assertEqual(2, mock_link.call_count)
call_1_args = mock_link.call_args_list[0][0]
self.assertEqual(call_1_args[0], from_unit.type_id)
self.assertEqual(call_1_args[1], from_unit.id)
self.assertEqual(call_1_args[2], to_unit.type_id)
self.assertEqual(call_1_args[3], [to_unit.id])
call_2_args = mock_link.call_args_list[1][0]
self.assertEqual(call_2_args[0], to_unit.type_id)
self.assertEqual(call_2_args[1], to_unit.id)
self.assertEqual(call_2_args[2], from_unit.type_id)
self.assertEqual(call_2_args[3], [from_unit.id])
示例8: test_unit_not_applicable_not_in_repo
# 需要导入模块: from pulp.plugins.model import Unit [as 别名]
# 或者: from pulp.plugins.model.Unit import id [as 别名]
def test_unit_not_applicable_not_in_repo(self):
# Errata refers to RPMs which ARE part of our test consumer's profile,
# but are not in the repo.
errata_obj = self.get_test_errata_object()
errata_unit = Unit(TYPE_ID_ERRATA, {"id": errata_obj["id"]}, errata_obj, None)
errata_unit.id = 'an_errata'
test_repo = profiler_mocks.get_repo("test_repo_id")
prof = YumProfiler()
errata_rpms = prof._get_rpms_from_errata(errata_unit)
conduit = profiler_mocks.get_profiler_conduit(repo_units=[errata_unit],
repo_bindings=[test_repo],
errata_rpms=errata_rpms)
unit_profile = self.test_consumer.profiles[TYPE_ID_RPM]
bound_repo_id = "test_repo_id"
report_list = prof.calculate_applicable_units(unit_profile, bound_repo_id, None, conduit)
self.assertEqual(report_list, {TYPE_ID_RPM: [], TYPE_ID_ERRATA: []})