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


Python Mock.uuid方法代码示例

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


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

示例1: test_calls_get_file_extension_by_content_type

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uuid [as 别名]
 def test_calls_get_file_extension_by_content_type(self, mock_func):
     file = Mock()
     file.uuid = ''
     file.content_type = 'foo'
     with self.assertRaises(FileNotFoundError):
         retrieve_file(file)
     mock_func.assert_called_once_with('foo')
开发者ID:CDE-UNIBE,项目名称:qcat,代码行数:9,代码来源:test_upload.py

示例2: test_uses_thumbnail_if_provided

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uuid [as 别名]
 def test_uses_thumbnail_if_provided(
         self, mock_get_upload_folder_structure):
     file = Mock()
     file.uuid = ''
     file.content_type = 'foo'
     file.thumbnails = {'bar': 'asdf'}
     with self.assertRaises(FileNotFoundError):
         retrieve_file(file, thumbnail='bar')
     mock_get_upload_folder_structure.assert_called_once_with('asdf')
开发者ID:CDE-UNIBE,项目名称:qcat,代码行数:11,代码来源:test_upload.py

示例3: test_sync_file_overwrite

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uuid [as 别名]
    def test_sync_file_overwrite(self, FileTransfer, Messanger_connect):
        remote = Mock()
        remote.address = '127.0.0.1'
        remote.my_uuid = 'my_uuid'
        remote.uuid = 'remote_uuid'

        file_transfer = MagicMock()
        FileTransfer.return_value = file_transfer

        file_transfer.get_remote_uuid.return_value = 'remote_uuid'
        file_transfer.file_name = 'file1'

        self.manager.sync_file(remote, 'file1')

        self.assertTrue(self.manager.transfers.has('file1', 'remote_uuid'))

        remote2 = Mock()
        remote2.address = '127.0.0.1'
        remote2.my_uuid = 'my_uuid'
        remote2.uuid = 'remote_uuid'

        file_transfer2 = MagicMock()
        FileTransfer.return_value = file_transfer2

        file_transfer2.get_remote_uuid.return_value = 'remote_uuid'
        file_transfer2.file_name = 'file1'
        file_transfer2.file_data = {
            'last_update': 1234
        }
        self.manager.directory.get_index.return_value = {
            'file1': {
                'last_update': 234
            }
        }

        self.manager.sync_file(remote2, 'file1')

        self.assertTrue(file_transfer.shutdown.called)
        self.assertTrue(file_transfer2.initialize.called)
        self.assertTrue(file_transfer2.start.called)
开发者ID:stormbreakerbg,项目名称:syncall,代码行数:42,代码来源:transfers.py

示例4: test_get_queued

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uuid [as 别名]
    def test_get_queued(self):
        remote = Mock()
        remote.uuid = 'uuid'
        self.manager.queue = {
            'uuid': {('file1', remote)}
        }
        self.manager.queued = {
            ('file1', 'uuid')
        }
        old = Mock()
        old.get_remote_uuid.return_value = 'uuid'

        queued = self.manager._TransferManager__get_queued(old)

        self.assertEqual(queued, (remote, 'file1'))
开发者ID:stormbreakerbg,项目名称:syncall,代码行数:17,代码来源:transfers.py

示例5: test_sync_new_file

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uuid [as 别名]
    def test_sync_new_file(self, FileTransfer, Messanger_connect):
        remote = Mock()
        remote.address = '127.0.0.1'
        remote.my_uuid = 'my_uuid'
        remote.uuid = 'remote_uuid'

        file_transfer = MagicMock()
        FileTransfer.return_value = file_transfer

        file_transfer.get_remote_uuid.return_value = 'remote_uuid'
        file_transfer.file_name = 'file1'

        self.manager.sync_file(remote, 'file1')

        self.assertTrue(self.manager.transfers.has('file1', 'remote_uuid'))
        self.assertTrue(
            self.manager.transfers.get('file1', 'remote_uuid').start.called
        )
        self.assertTrue(file_transfer.start.called)
        self.assertTrue(file_transfer.initialize.called)
开发者ID:stormbreakerbg,项目名称:syncall,代码行数:22,代码来源:transfers.py

示例6: test_remote_disconnect

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uuid [as 别名]
    def test_remote_disconnect(self):
        transfer_remote1 = Mock()
        transfer_remote1.get_remote_uuid.return_value = 'uuid1'

        transfer_remote2 = Mock()
        transfer_remote2.get_remote_uuid.return_value = 'uuid2'

        transfer_remote3 = Mock()
        transfer_remote3.get_remote_uuid.return_value = 'uuid1'

        self.manager.transfers = Mock()
        self.manager.transfers.get_all.return_value = [
            transfer_remote1, transfer_remote2, transfer_remote3
        ]

        remote = Mock()
        remote.uuid = 'uuid1'

        self.manager.remote_disconnect(remote)

        self.assertTrue(transfer_remote1.shutdown.called)
        self.assertFalse(transfer_remote2.shutdown.called)
        self.assertTrue(transfer_remote3.shutdown.called)
开发者ID:stormbreakerbg,项目名称:syncall,代码行数:25,代码来源:transfers.py

示例7: test_run

# 需要导入模块: from unittest.mock import Mock [as 别名]
# 或者: from unittest.mock.Mock import uuid [as 别名]
    def test_run(self, *args):
        """Test lvm format populator."""
        get_device_by_uuid = args[0]

        devicetree = DeviceTree()
        data = dict()
        device = Mock()
        device.parents = []
        device.size = Size("10g")
        devicetree._add_device(device)

        # pylint: disable=attribute-defined-outside-init
        self._pvs = blockdev.lvm.pvs
        self._vgs = blockdev.lvm.vgs
        self._lvs = blockdev.lvm.lvs
        blockdev.lvm.pvs = Mock(return_value=[])
        blockdev.lvm.vgs = Mock(return_value=[])
        blockdev.lvm.lvs = Mock(return_value=[])
        self.addCleanup(self._clean_up)

        # base case: pv format with no vg
        with patch("blivet.udev.device_get_format", return_value=self.udev_type):
            helper = self.helper_class(devicetree, data, device)
            helper.run()
            self.assertEqual(device.format.type,
                             self.blivet_type,
                             msg="Wrong format type after FormatPopulator.run on %s" % self.udev_type)

        # pv belongs to a valid vg which is already in the tree (no lvs)
        pv_info = Mock()

        pv_info.vg_name = "testvgname"
        pv_info.vg_uuid = sentinel.vg_uuid
        pv_info.pe_start = 0
        pv_info.pv_free = 0

        device.path = sentinel.pv_path

        vg_device = Mock()
        vg_device.parents = []
        vg_device.lvs = []
        get_device_by_uuid.return_value = vg_device

        with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache:
            mock_pvs_cache.return_value = {sentinel.pv_path: pv_info}
            with patch("blivet.udev.device_get_format", return_value=self.udev_type):
                helper = self.helper_class(devicetree, data, device)
                self.assertFalse(device in vg_device.parents)
                helper.run()
                self.assertEqual(device.format.type,
                                 self.blivet_type,
                                 msg="Wrong format type after FormatPopulator.run on %s" % self.udev_type)

                self.assertEqual(get_device_by_uuid.call_count, 3)
                get_device_by_uuid.assert_called_with(pv_info.vg_uuid, incomplete=True)
                self.assertTrue(device in vg_device.parents)

        get_device_by_uuid.reset_mock()
        get_device_by_uuid.return_value = None

        # pv belongs to a valid vg which is not in the tree (no lvs, either)
        pv_info.vg_size = "10g"
        pv_info.vg_free = 0
        pv_info.vg_extent_size = "4m"
        pv_info.vg_extent_count = 2500
        pv_info.vg_free_count = 0
        pv_info.vg_pv_count = 1

        with patch("blivet.static_data.lvm_info.PVsInfo.cache", new_callable=PropertyMock) as mock_pvs_cache:
            mock_pvs_cache.return_value = {sentinel.pv_path: pv_info}
            with patch("blivet.udev.device_get_format", return_value=self.udev_type):
                helper = self.helper_class(devicetree, data, device)
                helper.run()
                self.assertEqual(device.format.type,
                                 self.blivet_type,
                                 msg="Wrong format type after FormatPopulator.run on %s" % self.udev_type)

                self.assertEqual(get_device_by_uuid.call_count, 2)
                get_device_by_uuid.assert_called_with(pv_info.vg_uuid, incomplete=True)
                vg_device = devicetree.get_device_by_name(pv_info.vg_name)
                self.assertTrue(vg_device is not None)
                devicetree._remove_device(vg_device)

        get_device_by_uuid.reset_mock()

        # pv belongs to a valid vg not in the tree with two lvs
        lv1 = Mock()
        lv1.vg_name = pv_info.vg_name
        lv1.lv_name = "testlv1"
        lv1.uuid = sentinel.lv1_uuid
        lv1.attr = "-wi-ao----"
        lv1.size = "2g"
        lv1.segtype = "linear"
        lv1_name = "%s-%s" % (pv_info.vg_name, lv1.lv_name)

        lv2 = Mock()
        lv2.vg_name = pv_info.vg_name
        lv2.lv_name = "testlv2"
        lv2.uuid = sentinel.lv2_uuid
        lv2.attr = "-wi-ao----"
#.........这里部分代码省略.........
开发者ID:afamilyman,项目名称:blivet,代码行数:103,代码来源:populator_test.py


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