当前位置: 首页>>代码示例>>Python>>正文


Python OrphanManager.get_orphan方法代码示例

本文整理汇总了Python中pulp.server.managers.content.orphan.OrphanManager.get_orphan方法的典型用法代码示例。如果您正苦于以下问题:Python OrphanManager.get_orphan方法的具体用法?Python OrphanManager.get_orphan怎么用?Python OrphanManager.get_orphan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pulp.server.managers.content.orphan.OrphanManager的用法示例。


在下文中一共展示了OrphanManager.get_orphan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: OrphanManagerTests

# 需要导入模块: from pulp.server.managers.content.orphan import OrphanManager [as 别名]
# 或者: from pulp.server.managers.content.orphan.OrphanManager import get_orphan [as 别名]
class OrphanManagerTests(base.PulpServerTests):

    def setUp(self):
        super(OrphanManagerTests, self).setUp()
        content_type_db.update_database([PHONY_TYPE_1, PHONY_TYPE_2])
        self.content_root = tempfile.mkdtemp(prefix='content_orphan_manager_unittests-')
        self.orphan_manager = OrphanManager()

    def tearDown(self):
        super(OrphanManagerTests, self).tearDown()
        RepoContentUnit.get_collection().remove(safe=True)
        content_type_db.clean()
        if os.path.exists(self.content_root): # can be removed by delete operations
            shutil.rmtree(self.content_root)

    def number_of_files_in_content_root(self):
        if not os.path.exists(self.content_root): # can be removed by delete operations
            return 0
        contents = os.listdir(self.content_root)
        return len(contents)

    # utilities test methods ---------------------------------------------------

    def test_content_creation(self):
        self.assertTrue(self.number_of_files_in_content_root() == 0)
        content_unit = gen_content_unit(PHONY_TYPE_1.id, self.content_root)
        self.assertTrue(os.path.exists(content_unit['_storage_path']))
        self.assertTrue(self.number_of_files_in_content_root() == 1)

    # list test methods --------------------------------------------------------

    def test_list_one_orphan(self):
        orphans = self.orphan_manager.list_all_orphans()
        self.assertTrue(len(orphans) == 0)
        content_unit = gen_content_unit(PHONY_TYPE_1.id, self.content_root)
        orphans = self.orphan_manager.list_all_orphans()
        self.assertTrue(len(orphans) == 1)
        self.assertTrue(orphans[0]['_id'] == content_unit['_id'])

    def test_list_two_orphans(self):
        unit_1 = gen_content_unit(PHONY_TYPE_1.id, self.content_root)
        unit_2 = gen_content_unit(PHONY_TYPE_2.id, self.content_root)
        orphans = self.orphan_manager.list_all_orphans()
        self.assertTrue(len(orphans) == 2)

    def test_list_orphans_by_type(self):
        unit_1 = gen_content_unit(PHONY_TYPE_1.id, self.content_root)
        unit_2 = gen_content_unit(PHONY_TYPE_2.id, self.content_root)
        orphans_1 = self.orphan_manager.list_orphans_by_type(PHONY_TYPE_1.id)
        self.assertTrue(len(orphans_1) == 1)
        orphans_2 = self.orphan_manager.list_orphans_by_type(PHONY_TYPE_2.id)
        self.assertTrue(len(orphans_2) == 1)

    def test_get_orphan(self):
        unit = gen_content_unit(PHONY_TYPE_1.id, self.content_root)
        orphan = self.orphan_manager.get_orphan(PHONY_TYPE_1.id, unit['_id'])
        self.assertTrue(orphan['_id'] == unit['_id'])

    def test_get_missing_orphan(self):
        self.assertRaises(pulp_exceptions.MissingResource,
                          self.orphan_manager.get_orphan,
                          PHONY_TYPE_1.id, 'non-existent')

    def test_associated_unit(self):
        unit = gen_content_unit(PHONY_TYPE_1.id, self.content_root)
        associate_content_unit_with_repo(unit)
        orphans = self.orphan_manager.list_all_orphans()
        self.assertTrue(len(orphans) == 0)
        unassociate_content_unit_from_repo(unit)
        orphans = self.orphan_manager.list_all_orphans()
        self.assertTrue(len(orphans) == 1)

    # delete test methods ------------------------------------------------------

    def test_delete_one_orphan(self):
        unit = gen_content_unit(PHONY_TYPE_1.id, self.content_root)
        self.orphan_manager.delete_all_orphans()
        orphans = self.orphan_manager.list_all_orphans()
        self.assertTrue(len(orphans) == 0)
        self.assertTrue(self.number_of_files_in_content_root() == 0)

    def test_delete_one_orphan_with_directory(self):
        unit = gen_content_unit_with_directory(PHONY_TYPE_1.id, self.content_root)
        self.orphan_manager.delete_all_orphans()
        orphans = self.orphan_manager.list_all_orphans()
        self.assertTrue(len(orphans) == 0)
        self.assertTrue(self.number_of_files_in_content_root() == 0)

    def test_delete_by_type(self):
        unit_1 = gen_content_unit(PHONY_TYPE_1.id, self.content_root)
        unit_2 = gen_content_unit(PHONY_TYPE_2.id, self.content_root)
        self.assertTrue(self.number_of_files_in_content_root() == 2)
        self.orphan_manager.delete_orphans_by_type(PHONY_TYPE_1.id)
        orphans = self.orphan_manager.list_all_orphans()
        self.assertTrue(len(orphans) == 1)
        self.assertFalse(os.path.exists(unit_1['_storage_path']))
        self.assertTrue(os.path.exists(unit_2['_storage_path']))

    def test_delete_by_id(self):
        unit = gen_content_unit(PHONY_TYPE_1.id, self.content_root)
#.........这里部分代码省略.........
开发者ID:domcleal,项目名称:pulp,代码行数:103,代码来源:test_content_orphan_manager.py


注:本文中的pulp.server.managers.content.orphan.OrphanManager.get_orphan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。