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


Python SwiftService._upload_segment_job方法代码示例

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


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

示例1: test_upload_segment_job

# 需要导入模块: from swiftclient.service import SwiftService [as 别名]
# 或者: from swiftclient.service.SwiftService import _upload_segment_job [as 别名]
    def test_upload_segment_job(self):
        with tempfile.NamedTemporaryFile() as f:
            f.write(b'a' * 10)
            f.write(b'b' * 10)
            f.write(b'c' * 10)
            f.flush()

            # Mock the connection to return an empty etag. This
            # skips etag validation which would fail as the LengthWrapper
            # isnt read from.
            mock_conn = mock.Mock()
            mock_conn.put_object.return_value = ''
            type(mock_conn).attempts = mock.PropertyMock(return_value=2)
            expected_r = {
                'action': 'upload_segment',
                'for_object': 'test_o',
                'segment_index': 2,
                'segment_size': 10,
                'segment_location': '/test_c_segments/test_s_1',
                'log_line': 'test_o segment 2',
                'success': True,
                'response_dict': {},
                'segment_etag': '',
                'attempts': 2,
            }

            s = SwiftService()
            r = s._upload_segment_job(conn=mock_conn,
                                      path=f.name,
                                      container='test_c',
                                      segment_name='test_s_1',
                                      segment_start=10,
                                      segment_size=10,
                                      segment_index=2,
                                      obj_name='test_o',
                                      options={'segment_container': None,
                                               'checksum': True})

            self._assertDictEqual(r, expected_r)

            self.assertEqual(mock_conn.put_object.call_count, 1)
            mock_conn.put_object.assert_called_with('test_c_segments',
                                                    'test_s_1',
                                                    mock.ANY,
                                                    content_length=10,
                                                    response_dict={})
            contents = mock_conn.put_object.call_args[0][2]
            self.assertIsInstance(contents, utils.LengthWrapper)
            self.assertEqual(len(contents), 10)
            # This read forces the LengthWrapper to calculate the md5
            # for the read content.
            self.assertEqual(contents.read(), b'b' * 10)
            self.assertEqual(contents.get_md5sum(), md5(b'b' * 10).hexdigest())
开发者ID:alkivi-sas,项目名称:python-swiftclient,代码行数:55,代码来源:test_service.py

示例2: test_upload_segment_job_etag_mismatch

# 需要导入模块: from swiftclient.service import SwiftService [as 别名]
# 或者: from swiftclient.service.SwiftService import _upload_segment_job [as 别名]
    def test_upload_segment_job_etag_mismatch(self):
        def _consuming_conn(*a, **kw):
            contents = a[2]
            contents.read()  # Force md5 calculation
            return 'badresponseetag'

        with tempfile.NamedTemporaryFile() as f:
            f.write(b'a' * 10)
            f.write(b'b' * 10)
            f.write(b'c' * 10)
            f.flush()

            mock_conn = mock.Mock()
            mock_conn.put_object.side_effect = _consuming_conn
            type(mock_conn).attempts = mock.PropertyMock(return_value=2)

            s = SwiftService()
            r = s._upload_segment_job(conn=mock_conn,
                                      path=f.name,
                                      container='test_c',
                                      segment_name='test_s_1',
                                      segment_start=10,
                                      segment_size=10,
                                      segment_index=2,
                                      obj_name='test_o',
                                      options={'segment_container': None,
                                               'checksum': True})

            self.assertIn('error', r)
            self.assertIn('md5 mismatch', str(r['error']))

            self.assertEqual(mock_conn.put_object.call_count, 1)
            mock_conn.put_object.assert_called_with('test_c_segments',
                                                    'test_s_1',
                                                    mock.ANY,
                                                    content_length=10,
                                                    response_dict={})
            contents = mock_conn.put_object.call_args[0][2]
            self.assertEqual(contents.get_md5sum(), md5(b'b' * 10).hexdigest())
开发者ID:alkivi-sas,项目名称:python-swiftclient,代码行数:41,代码来源:test_service.py


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