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


Python MigrationModule._decode_changelog方法代码示例

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


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

示例1: TestMigrationAddMetadata

# 需要导入模块: from pulp.server.db.migrate.models import MigrationModule [as 别名]
# 或者: from pulp.server.db.migrate.models.MigrationModule import _decode_changelog [as 别名]
class TestMigrationAddMetadata(rpm_support_base.PulpRPMTests):
    def setUp(self):
        super(TestMigrationAddMetadata, self).setUp()
        self.module = MigrationModule('pulp_rpm.migrations.0005_rpm_changelog_files')._module

        self.fake_unit = {'_storage_path': '/tmp/foo'}
        self.mock_ts = mock.MagicMock()
        self.mock_collection = mock.MagicMock()

        self.mock_package = mock.MagicMock()
        self.mock_package.changelog = [('now', '[email protected]', 'description'),]
        self.mock_package.filelist = ['/a', '/b', '/c']
        self.mock_package.files = {
            'ghost': ['/xyz'],
            'dir': ['/foo', '/bar'],
            'file': ['/a', '/b', '/c'],
        }

    def verify_saved_unit(self, saved_unit):
        self.assertTrue('files' in saved_unit)
        for key, value in saved_unit['files'].iteritems():
            for item in value:
                self.assertTrue(isinstance(item, unicode))

        self.assertTrue('filelist' in saved_unit)
        for value in saved_unit['filelist']:
            self.assertTrue(isinstance(value, unicode))

        self.assertTrue('changelog' in saved_unit)
        for entry in saved_unit['changelog']:
            # don't inspect timestamp, which is the first item
            for item in entry[1:]:
                self.assertTrue(isinstance(item, unicode))
        # this is how mongo will encode it, so make sure this is possible
        BSON.encode(saved_unit)

    @mock.patch('os.path.exists', return_value=True)
    @mock.patch('createrepo.yumbased.CreateRepoPackage')
    def test_migrate_filelist(self, mock_package_class, mock_exists):
        mock_package_class.return_value = self.mock_package

        self.module._migrate_unit(self.fake_unit, self.mock_ts, self.mock_collection)

        self.assertEqual(self.mock_collection.save.call_count, 1)
        saved_unit = self.mock_collection.save.call_args[0][0]
        self.verify_saved_unit(saved_unit)
        self.assertEqual(saved_unit['files'], self.mock_package.files)
        self.assertEqual(saved_unit['filelist'], self.mock_package.filelist)
        self.assertEqual(
            saved_unit['changelog'][0],
            self.module._decode_changelog(self.mock_package.changelog[0])
        )

    def test_with_real_packages(self):
        current_dir = os.path.dirname(__file__)
        paths = glob.glob(os.path.join(
            current_dir,
            '../../data/repos.fedorapeople.org/repos/pulp/pulp/demo_repos/zoo/*.rpm'
        ))
        ts = transaction.initReadOnlyTransaction()

        for path in paths:
            fake_unit = {'_storage_path': path}
            self.module._migrate_unit(fake_unit, ts, self.mock_collection)
            saved_unit = self.mock_collection.save.call_args[0][0]
            self.verify_saved_unit(saved_unit)

    @mock.patch('os.path.exists', return_value=True)
    @mock.patch('createrepo.yumbased.CreateRepoPackage')
    def test_latin1_metadata(self, mock_package_class, mock_exists):
        # the following string cannot be decoded as utf8, so this checks that the
        # migration handles latin1 decoding also. Mongo will barf if we hand it
        # this string.
        self.mock_package.filelist.append('/usr/share/doc/man-pages-da-0.1.1/l\xe6smig')
        mock_package_class.return_value = self.mock_package
        self.module._migrate_unit(self.fake_unit, self.mock_ts, self.mock_collection)

        saved_unit = self.mock_collection.save.call_args[0][0]
        self.verify_saved_unit(saved_unit)
开发者ID:bechtoldt,项目名称:pulp_rpm,代码行数:81,代码来源:test_0005_migrate.py


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