本文整理汇总了Python中mock.MagicMock.timeout方法的典型用法代码示例。如果您正苦于以下问题:Python MagicMock.timeout方法的具体用法?Python MagicMock.timeout怎么用?Python MagicMock.timeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mock.MagicMock
的用法示例。
在下文中一共展示了MagicMock.timeout方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_blobchunkworker_run
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_blobchunkworker_run(tmpdir):
lpath = str(tmpdir.join("test.tmp"))
with open(lpath, "wt") as f:
f.write(str(uuid.uuid4()))
args = MagicMock()
args.pageblob = True
args.autovhd = False
args.timeout = None
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount("mock", adapter)
exc_list = []
flock = threading.Lock()
sa_in_queue = queue.Queue()
sa_out_queue = queue.Queue()
with requests_mock.mock() as m:
m.put("mock://blobepcontainer/blob?saskey", status_code=200)
sbs = blobxfer.SasBlobService("mock://blobep", "saskey", None)
bcw = blobxfer.BlobChunkWorker(exc_list, sa_in_queue, sa_out_queue, args, sbs, True)
with pytest.raises(IOError):
bcw.putblobdata(lpath, "container", "blob", "blockid", 0, 4, flock, None)
args.pageblob = False
with requests_mock.mock() as m:
m.put("mock://blobepcontainer/blob?saskey", status_code=201)
sbs = blobxfer.SasBlobService("mock://blobep", "saskey", None)
bcw = blobxfer.BlobChunkWorker(exc_list, sa_in_queue, sa_out_queue, args, sbs, True)
try:
bcw.putblobdata(lpath, "container", "blob", "blockid", 0, 4, flock, None)
except Exception:
pytest.fail("unexpected Exception raised")
m.get("mock://blobepcontainer/blob?saskey", status_code=200)
try:
bcw.getblobrange(lpath, "container", "blob", 0, 4, flock, None)
except Exception:
pytest.fail("unexpected Exception raised")
# test zero-length putblob
bcw.putblobdata(lpath, "container", "blob", "blockid", 0, 0, flock, None)
bcw._pageblob = True
bcw.putblobdata(lpath, "container", "blob", "blockid", 0, 0, flock, None)
# test empty page
with open(lpath, "wb") as f:
f.write(b"\0" * 4 * 1024 * 1024)
bcw.putblobdata(lpath, "container", "blob", "blockid", 0, 4 * 1024 * 1024, flock, None)
with open(lpath, "wb") as f:
f.write(b"\0" * 4 * 1024)
bcw.putblobdata(lpath, "container", "blob", "blockid", 0, 4 * 1024, flock, None)
sa_in_queue.put((lpath, "container", "blob", "blockid", 0, 4, flock, None))
with requests_mock.mock() as m:
sbs = blobxfer.SasBlobService("mock://blobep", "saskey", None)
bcw = blobxfer.BlobChunkWorker(exc_list, sa_in_queue, sa_out_queue, args, sbs, False)
m.get("mock://blobepcontainer/blob?saskey", status_code=201)
bcw.run()
assert len(exc_list) > 0
示例2: test_blobchunkworker_run
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_blobchunkworker_run(tmpdir):
lpath = str(tmpdir.join('test.tmp'))
with open(lpath, 'wt') as f:
f.write(str(uuid.uuid4()))
exc_list = []
sa_in_queue = queue.Queue()
sa_out_queue = queue.Queue()
flock = threading.Lock()
sa_in_queue.put((True, lpath, 'blobep', 'saskey', 'container',
'blob', 'blockid', 0, 4, flock, None))
sa_in_queue.put((False, lpath, 'blobep', 'saskey', 'container',
'blob', 'blockid', 0, 4, flock, None))
args = MagicMock()
args.pageblob = False
args.autovhd = False
args.timeout = None
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount('mock', adapter)
with requests_mock.mock() as m:
m.put('mock://blobepcontainer/blob?saskey', status_code=201)
sbs = blobxfer.SasBlobService('mock://blobep', 'saskey', None)
bcw = blobxfer.BlobChunkWorker(
exc_list, sa_in_queue, sa_out_queue, args, sbs)
try:
bcw.putblobdata(lpath, 'container', 'blob', 'blockid',
0, 4, flock, None)
except Exception:
pytest.fail('unexpected Exception raised')
m.get('mock://blobepcontainer/blob?saskey', status_code=200)
try:
bcw.getblobrange(lpath, 'container', 'blob', 0, 4, flock, None)
except Exception:
pytest.fail('unexpected Exception raised')
m.get('mock://blobepcontainer/blob?saskey', status_code=201)
bcw.run()
assert len(exc_list) > 0
exc_list = []
sa_in_queue = queue.Queue()
sa_out_queue = queue.Queue()
sa_in_queue.put((True, lpath, 'blobep', 'saskey', 'container',
'blob', 'blockid', 0, 4, flock, None))
sa_in_queue.put((False, lpath, 'blobep', 'saskey', 'container',
'blob', 'blockid', 0, 4, flock, None))
args.pageblob = True
with requests_mock.mock() as m:
m.put('mock://blobepcontainer/blob?saskey', status_code=200)
sbs = blobxfer.SasBlobService('mock://blobep', 'saskey', None)
bcw = blobxfer.BlobChunkWorker(
exc_list, sa_in_queue, sa_out_queue, args, sbs)
with pytest.raises(IOError):
bcw.putblobdata(lpath, 'container', 'blob', 'blockid',
0, 4, flock, None)
示例3: test_generate_xferspec_download_invalid
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_generate_xferspec_download_invalid(patched_azure_request):
args = MagicMock()
args.storageaccount = "blobep"
args.container = "container"
args.storageaccountkey = "saskey"
args.chunksizebytes = 5
args.timeout = None
sa_in_queue = queue.Queue()
with requests_mock.mock() as m:
m.head("mock://blobepcontainer/blob?saskey", headers={"content-length": "-1", "content-md5": "md5"})
sbs = blobxfer.SasBlobService("mock://blobep", "saskey", None)
with pytest.raises(ValueError):
blobxfer.generate_xferspec_download(sbs, args, sa_in_queue, "tmppath", "blob", None, None, True)
示例4: test_generate_xferspec_download_invalid
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_generate_xferspec_download_invalid(patched_azure_request):
args = MagicMock()
args.storageaccount = 'blobep'
args.container = 'container'
args.storageaccountkey = 'saskey'
args.chunksizebytes = 5
args.timeout = None
sa_in_queue = queue.Queue()
with requests_mock.mock() as m:
m.head('mock://blobepcontainer/blob?saskey', headers={
'content-length': '-1', 'content-md5': 'md5'})
sbs = blobxfer.SasBlobService('mock://blobep', 'saskey', None)
with pytest.raises(ValueError):
blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, 'tmppath', 'blob', None, None, True)
示例5: test_main2
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_main2(patched_parseargs, tmpdir):
lpath = str(tmpdir.join('test.tmp'))
args = MagicMock()
patched_parseargs.return_value = args
args.include = None
args.stripcomponents = 1
args.delete = False
args.rsaprivatekey = None
args.rsapublickey = None
args.numworkers = 64
args.storageaccount = 'blobep'
args.container = 'container'
args.chunksizebytes = 5
args.localresource = lpath
args.blobep = '.blobep'
args.timeout = 10
args.pageblob = False
args.autovhd = False
args.managementep = None
args.managementcert = None
args.subscriptionid = None
args.chunksizebytes = None
args.download = False
args.upload = True
args.remoteresource = None
args.saskey = None
args.storageaccountkey = 'key'
with open(lpath, 'wt') as f:
f.write(str(uuid.uuid4()))
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount('mock', adapter)
with patch('azure.storage.blob.BlobService') as mock:
args.createcontainer = True
args.pageblob = False
args.autovhd = False
args.collate = None
mock.return_value = MagicMock()
mock.return_value.create_container = _mock_blobservice_create_container
blobxfer.main()
args.createcontainer = False
args.pageblob = True
args.autovhd = False
blobxfer.main()
示例6: test_main2
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_main2(patched_parseargs, tmpdir):
lpath = str(tmpdir.join("test.tmp"))
args = MagicMock()
patched_parseargs.return_value = args
args.numworkers = 64
args.storageaccount = "blobep"
args.container = "container"
args.chunksizebytes = 5
args.localresource = lpath
args.blobep = ".blobep"
args.timeout = 10
args.pageblob = False
args.autovhd = False
args.managementep = None
args.managementcert = None
args.subscriptionid = None
args.chunksizebytes = None
args.download = False
args.upload = True
args.remoteresource = None
args.saskey = None
args.storageaccountkey = "key"
with open(lpath, "wt") as f:
f.write(str(uuid.uuid4()))
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount("mock", adapter)
with patch("azure.storage.blob.BlobService") as mock:
args.createcontainer = True
args.pageblob = False
args.autovhd = False
args.keeprootdir = False
args.collate = None
mock.return_value = MagicMock()
mock.return_value.create_container = _mock_blobservice_create_container
blobxfer.main()
args.createcontainer = False
args.pageblob = True
args.autovhd = False
blobxfer.main()
示例7: test_generate_xferspec_download
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_generate_xferspec_download(tmpdir):
lpath = str(tmpdir.join("test.tmp"))
args = MagicMock()
args.storageaccount = "blobep"
args.container = "container"
args.storageaccountkey = "saskey"
args.chunksizebytes = 5
args.timeout = None
sa_in_queue = queue.Queue()
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount("mock", adapter)
with requests_mock.mock() as m:
m.head("mock://blobepcontainer/blob?saskey", headers={"content-length": "-1", "content-md5": "md5"})
sbs = blobxfer.SasBlobService("mock://blobep", "saskey", None)
with pytest.raises(ValueError):
blobxfer.generate_xferspec_download(sbs, args, sa_in_queue, lpath, "blob", None, None, True)
m.head("mock://blobepcontainer/blob?saskey", headers={"content-length": "6", "content-md5": "md5"})
cl, nsops, md5, fd = blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, "blob", None, None, True
)
assert 6 == cl
assert 2 == nsops
assert "md5" == md5
assert None != fd
fd.close()
cl, nsops, md5, fd = blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, "blob", None, None, False
)
assert None == fd
with open(lpath, "wt") as f:
f.write("012345")
m.head(
"mock://blobepcontainer/blob?saskey",
headers={"content-length": "6", "content-md5": "1qmpM8iq/FHlWsBmK25NSg=="},
)
cl, nsops, md5, fd = blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, "blob", None, None, True
)
assert cl is None
示例8: test_generate_xferspec_download
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_generate_xferspec_download(tmpdir):
lpath = str(tmpdir.join('test.tmp'))
args = MagicMock()
args.storageaccount = 'blobep'
args.container = 'container'
args.storageaccountkey = 'saskey'
args.chunksizebytes = 5
args.timeout = None
sa_in_queue = queue.Queue()
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount('mock', adapter)
with requests_mock.mock() as m:
m.head('mock://blobepcontainer/blob?saskey', headers={
'content-length': '-1', 'content-md5': 'md5'})
sbs = blobxfer.SasBlobService('mock://blobep', 'saskey', None)
with pytest.raises(ValueError):
blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, 'blob', None, None, True)
m.head('mock://blobepcontainer/blob?saskey', headers={
'content-length': '6', 'content-md5': 'md5'})
cl, nsops, md5, fd = blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, 'blob', None, None, True)
assert 6 == cl
assert 2 == nsops
assert 'md5' == md5
assert None != fd
fd.close()
cl, nsops, md5, fd = blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, 'blob', None, None, False)
assert None == fd
with open(lpath, 'wt') as f:
f.write('012345')
m.head('mock://blobepcontainer/blob?saskey', headers={
'content-length': '6', 'content-md5': '1qmpM8iq/FHlWsBmK25NSg=='})
cl, nsops, md5, fd = blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, 'blob', None, None, True)
assert cl is None
示例9: test_main1
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_main1(patched_parseargs, tmpdir):
lpath = str(tmpdir.join('test.tmp'))
args = MagicMock()
args.numworkers = 0
args.localresource = ''
args.storageaccount = 'blobep'
args.container = 'container'
args.storageaccountkey = 'saskey'
args.chunksizebytes = 5
args.pageblob = False
args.autovhd = False
patched_parseargs.return_value = args
with pytest.raises(ValueError):
blobxfer.main()
args.localresource = lpath
args.blobep = ''
with pytest.raises(ValueError):
blobxfer.main()
args.blobep = 'blobep'
args.upload = True
args.download = True
with pytest.raises(ValueError):
blobxfer.main()
args.upload = None
args.download = None
with pytest.raises(ValueError):
blobxfer.main()
args.storageaccountkey = None
args.timeout = -1
args.saskey = ''
with pytest.raises(ValueError):
blobxfer.main()
args.saskey = None
args.storageaccountkey = None
args.managementcert = 'cert.spam'
args.subscriptionid = '1234'
with pytest.raises(ValueError):
blobxfer.main()
args.managementcert = 'cert.pem'
args.managementep = None
with pytest.raises(ValueError):
blobxfer.main()
args.managementep = 'mep'
args.subscriptionid = None
with pytest.raises(ValueError):
blobxfer.main()
args.subscriptionid = '1234'
args.pageblob = True
args.autovhd = True
with pytest.raises(ValueError):
blobxfer.main()
args.pageblob = False
args.autovhd = False
with patch('azure.servicemanagement.ServiceManagementService') as mock:
mock.return_value = MagicMock()
mock.return_value.get_storage_account_keys = \
_mock_get_storage_account_keys
mock.return_value.get_storage_account_properties = \
_mock_get_storage_account_properties
with pytest.raises(ValueError):
blobxfer.main()
args.managementep = None
args.managementcert = None
args.subscriptionid = None
args.remoteresource = 'blob'
args.chunksizebytes = None
with patch('azure.storage.blob.BlobService') as mock:
mock.return_value = None
with pytest.raises(ValueError):
blobxfer.main()
args.storageaccountkey = None
args.saskey = 'saskey'
args.remoteresource = None
args.download = True
with pytest.raises(ValueError):
blobxfer.main()
args.download = False
args.upload = True
args.remoteresource = None
args.storageaccountkey = ''
args.saskey = None
with pytest.raises(ValueError):
blobxfer.main()
args.storageaccountkey = None
args.saskey = 'saskey'
with open(lpath, 'wt') as f:
f.write(str(uuid.uuid4()))
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount('mock', adapter)
with requests_mock.mock() as m:
m.put('https://blobep.blobep/container/blob?saskey'
'&comp=block&blockid=00000000', status_code=201)
m.put('https://blobep.blobep/container/' + lpath +
'?saskey&blockid=00000000&comp=block', status_code=201)
m.put('https://blobep.blobep/container/' + lpath +
'?saskey&comp=blocklist', status_code=201)
#.........这里部分代码省略.........
示例10: test_main1
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_main1(
patched_sms_saprops, patched_sms_sakeys, patched_parseargs, tmpdir):
lpath = str(tmpdir.join('test.tmp'))
args = MagicMock()
args.include = None
args.stripcomponents = 0
args.delete = False
args.rsaprivatekey = None
args.rsapublickey = None
args.rsakeypassphrase = None
args.numworkers = 0
args.localresource = ''
args.storageaccount = 'blobep'
args.container = 'container'
args.storageaccountkey = 'saskey'
args.chunksizebytes = 5
args.pageblob = False
args.autovhd = False
patched_parseargs.return_value = args
with pytest.raises(ValueError):
blobxfer.main()
args.localresource = lpath
args.blobep = ''
with pytest.raises(ValueError):
blobxfer.main()
args.blobep = 'blobep'
args.upload = True
args.download = True
with pytest.raises(ValueError):
blobxfer.main()
args.upload = None
args.download = None
with pytest.raises(ValueError):
blobxfer.main()
args.storageaccountkey = None
args.timeout = -1
args.saskey = ''
with pytest.raises(ValueError):
blobxfer.main()
args.saskey = None
args.storageaccountkey = None
args.managementcert = 'cert.spam'
args.subscriptionid = '1234'
with pytest.raises(ValueError):
blobxfer.main()
args.managementcert = 'cert.pem'
args.managementep = None
with pytest.raises(ValueError):
blobxfer.main()
args.managementep = 'mep'
args.subscriptionid = None
with pytest.raises(ValueError):
blobxfer.main()
args.subscriptionid = '1234'
args.pageblob = True
args.autovhd = True
with pytest.raises(ValueError):
blobxfer.main()
args.pageblob = False
args.autovhd = False
with patch('azure.servicemanagement.ServiceManagementService') as mock:
mock.return_value = MagicMock()
mock.return_value.get_storage_account_keys = \
_mock_get_storage_account_keys
mock.return_value.get_storage_account_properties = \
_mock_get_storage_account_properties
with pytest.raises(ValueError):
blobxfer.main()
args.managementep = None
args.managementcert = None
args.subscriptionid = None
args.remoteresource = 'blob'
args.chunksizebytes = None
with patch('azure.storage.blob.BlobService') as mock:
mock.return_value = None
with pytest.raises(ValueError):
blobxfer.main()
args.storageaccountkey = None
args.saskey = 'saskey'
args.remoteresource = None
args.download = True
with pytest.raises(ValueError):
blobxfer.main()
args.download = False
args.upload = True
args.remoteresource = None
args.storageaccountkey = ''
args.saskey = None
with pytest.raises(ValueError):
blobxfer.main()
args.collate = 'collatetmp'
with pytest.raises(ValueError):
blobxfer.main()
args.collate = None
args.storageaccountkey = None
args.saskey = ''
with pytest.raises(ValueError):
#.........这里部分代码省略.........
示例11: test_generate_xferspec_download
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_generate_xferspec_download(tmpdir):
lpath = str(tmpdir.join('test.tmp'))
args = MagicMock()
args.rsakey = None
args.storageaccount = 'blobep'
args.container = 'container'
args.storageaccountkey = 'saskey'
args.chunksizebytes = 5
args.timeout = None
sa_in_queue = queue.PriorityQueue()
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount('mock', adapter)
with requests_mock.mock() as m:
m.head('mock://blobepcontainer/blob?saskey', headers={
'content-length': '-1', 'content-md5': 'md5'})
sbs = blobxfer.SasBlobService('mock://blobep', 'saskey', None)
with pytest.raises(ValueError):
blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, 'blob', True,
[None, None, None])
assert sa_in_queue.qsize() == 0
m.head('mock://blobepcontainer/blob?saskey', headers={
'content-length': '6', 'content-md5': 'md5'})
cl, nsops, md5, fd = blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, 'blob', True, [None, None, None])
assert sa_in_queue.qsize() == 2
assert 2 == nsops
assert 6 == cl
assert 2 == nsops
assert 'md5' == md5
assert fd is not None
fd.close()
cl, nsops, md5, fd = blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, 'blob', False, [None, None, None])
assert 2 == nsops
assert fd is None
assert sa_in_queue.qsize() == 4
with open(lpath, 'wt') as f:
f.write('012345')
m.head('mock://blobepcontainer/blob?saskey', headers={
'content-length': '6', 'content-md5': '1qmpM8iq/FHlWsBmK25NSg=='})
cl, nsops, md5, fd = blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, 'blob', True, [None, None, None])
assert nsops is None
assert cl is None
assert sa_in_queue.qsize() == 4
sa_in_queue = queue.PriorityQueue()
args.rsaprivatekey = _RSAKEY
args.rsapublickey = None
symkey, signkey = blobxfer.generate_aes256_keys()
args.encmode = blobxfer._ENCRYPTION_MODE_CHUNKEDBLOB
metajson = blobxfer.EncryptionMetadataJson(
args, symkey, signkey, iv=b'0', encdata_signature=b'0',
preencrypted_md5=None)
encmeta = metajson.construct_metadata_json()
goodencjson = json.loads(encmeta[blobxfer._ENCRYPTION_METADATA_NAME])
goodauthjson = json.loads(
encmeta[blobxfer._ENCRYPTION_METADATA_AUTH_NAME])
metajson2 = blobxfer.EncryptionMetadataJson(
args, None, None, None, None, None)
metajson2.parse_metadata_json(
'blob', args.rsaprivatekey, args.rsapublickey, encmeta)
assert metajson2.symkey == symkey
assert metajson2.signkey == signkey
assert metajson2.encmode == args.encmode
assert metajson2.chunksizebytes == args.chunksizebytes + \
blobxfer._AES256CBC_HMACSHA256_OVERHEAD_BYTES + 1
encjson = json.loads(encmeta[blobxfer._ENCRYPTION_METADATA_NAME])
encjson[blobxfer._ENCRYPTION_METADATA_LAYOUT][
blobxfer._ENCRYPTION_METADATA_CHUNKSTRUCTURE] = 'X'
headers = {
'content-length': '64',
'content-md5': 'md5',
'x-ms-meta-' + blobxfer._ENCRYPTION_METADATA_NAME:
json.dumps(encjson),
'x-ms-meta-' + blobxfer._ENCRYPTION_METADATA_AUTH_NAME:
json.dumps(goodauthjson),
}
m.head('mock://blobepcontainer/blob?saskey', headers=headers)
with pytest.raises(RuntimeError):
blobxfer.generate_xferspec_download(
sbs, args, sa_in_queue, lpath, 'blob', False,
[None, None, None])
# switch to full blob mode tests
args.encmode = blobxfer._ENCRYPTION_MODE_FULLBLOB
metajson = blobxfer.EncryptionMetadataJson(
args, symkey, signkey, iv=b'0', encdata_signature=b'0',
preencrypted_md5=None)
encmeta = metajson.construct_metadata_json()
goodencjson = json.loads(encmeta[blobxfer._ENCRYPTION_METADATA_NAME])
goodauthjson = json.loads(
encmeta[blobxfer._ENCRYPTION_METADATA_AUTH_NAME])
headers['x-ms-meta-' + blobxfer._ENCRYPTION_METADATA_NAME] = \
json.dumps(goodencjson)
headers['x-ms-meta-' + blobxfer._ENCRYPTION_METADATA_AUTH_NAME] = \
#.........这里部分代码省略.........
示例12: test_blobchunkworker_run
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_blobchunkworker_run(tmpdir):
lpath = str(tmpdir.join('test.tmp'))
with open(lpath, 'wt') as f:
f.write(str(uuid.uuid4()))
args = MagicMock()
args.rsakey = None
args.pageblob = True
args.autovhd = False
args.timeout = None
session = requests.Session()
adapter = requests_mock.Adapter()
session.mount('mock', adapter)
exc_list = []
flock = threading.Lock()
sa_in_queue = queue.PriorityQueue()
sa_out_queue = queue.Queue()
with requests_mock.mock() as m:
m.put('mock://blobepcontainer/blob?saskey', status_code=200)
sbs = blobxfer.SasBlobService('mock://blobep', 'saskey', None)
bcw = blobxfer.BlobChunkWorker(
exc_list, sa_in_queue, sa_out_queue, args, sbs, True)
with pytest.raises(IOError):
bcw.putblobdata(lpath, 'container', 'blob', 'blockid',
0, 4, None, flock, None)
args.pageblob = False
with requests_mock.mock() as m:
m.put('mock://blobepcontainer/blob?saskey', status_code=201)
sbs = blobxfer.SasBlobService('mock://blobep', 'saskey', None)
bcw = blobxfer.BlobChunkWorker(
exc_list, sa_in_queue, sa_out_queue, args, sbs, True)
bcw.putblobdata(lpath, 'container', 'blob', 'blockid',
0, 4, None, flock, None)
m.get('mock://blobepcontainer/blob?saskey', status_code=200)
bcw.getblobrange(lpath, 'container', 'blob', 0, 0, 4,
[None, None, None, None, None, False], flock, None)
# test zero-length putblob
bcw.putblobdata(
lpath, 'container', 'blob', 'blockid', 0, 0, None, flock, None)
bcw._pageblob = True
bcw.putblobdata(
lpath, 'container', 'blob', 'blockid', 0, 0, None, flock, None)
# test empty page
with open(lpath, 'wb') as f:
f.write(b'\0' * 4 * 1024 * 1024)
bcw.putblobdata(
lpath, 'container', 'blob', 'blockid', 0, 4 * 1024 * 1024,
None, flock, None)
with open(lpath, 'wb') as f:
f.write(b'\0' * 4 * 1024)
bcw.putblobdata(
lpath, 'container', 'blob', 'blockid', 0, 4 * 1024,
None, flock, None)
sa_in_queue.put((0, (lpath, 'container', 'blob', 'blockid', 0, 4,
[None, None, None, None], flock, None)))
with requests_mock.mock() as m:
sbs = blobxfer.SasBlobService('mock://blobep', 'saskey', None)
bcw = blobxfer.BlobChunkWorker(
exc_list, sa_in_queue, sa_out_queue, args, sbs, False)
m.get('mock://blobepcontainer/blob?saskey', status_code=201)
bcw.run()
assert len(exc_list) > 0
示例13: test_main1
# 需要导入模块: from mock import MagicMock [as 别名]
# 或者: from mock.MagicMock import timeout [as 别名]
def test_main1(patched_sms_saprops, patched_sms_sakeys, patched_parseargs, tmpdir):
lpath = str(tmpdir.join("test.tmp"))
args = MagicMock()
args.numworkers = 0
args.localresource = ""
args.storageaccount = "blobep"
args.container = "container"
args.storageaccountkey = "saskey"
args.chunksizebytes = 5
args.pageblob = False
args.autovhd = False
patched_parseargs.return_value = args
with pytest.raises(ValueError):
blobxfer.main()
args.localresource = lpath
args.blobep = ""
with pytest.raises(ValueError):
blobxfer.main()
args.blobep = "blobep"
args.upload = True
args.download = True
with pytest.raises(ValueError):
blobxfer.main()
args.upload = None
args.download = None
with pytest.raises(ValueError):
blobxfer.main()
args.storageaccountkey = None
args.timeout = -1
args.saskey = ""
with pytest.raises(ValueError):
blobxfer.main()
args.saskey = None
args.storageaccountkey = None
args.managementcert = "cert.spam"
args.subscriptionid = "1234"
with pytest.raises(ValueError):
blobxfer.main()
args.managementcert = "cert.pem"
args.managementep = None
with pytest.raises(ValueError):
blobxfer.main()
args.managementep = "mep"
args.subscriptionid = None
with pytest.raises(ValueError):
blobxfer.main()
args.subscriptionid = "1234"
args.pageblob = True
args.autovhd = True
with pytest.raises(ValueError):
blobxfer.main()
args.pageblob = False
args.autovhd = False
with patch("azure.servicemanagement.ServiceManagementService") as mock:
mock.return_value = MagicMock()
mock.return_value.get_storage_account_keys = _mock_get_storage_account_keys
mock.return_value.get_storage_account_properties = _mock_get_storage_account_properties
with pytest.raises(ValueError):
blobxfer.main()
args.managementep = None
args.managementcert = None
args.subscriptionid = None
args.remoteresource = "blob"
args.chunksizebytes = None
with patch("azure.storage.blob.BlobService") as mock:
mock.return_value = None
with pytest.raises(ValueError):
blobxfer.main()
args.storageaccountkey = None
args.saskey = "saskey"
args.remoteresource = None
args.download = True
with pytest.raises(ValueError):
blobxfer.main()
args.download = False
args.upload = True
args.remoteresource = None
args.storageaccountkey = ""
args.saskey = None
with pytest.raises(ValueError):
blobxfer.main()
args.keeprootdir = True
args.collate = "collatetmp"
with pytest.raises(ValueError):
blobxfer.main()
args.keeprootdir = False
args.collate = None
args.storageaccountkey = None
args.saskey = ""
with pytest.raises(ValueError):
blobxfer.main()
args.saskey = None
with pytest.raises(ValueError):
blobxfer.main()
args.managementcert = "0"
args.managementep = ""
#.........这里部分代码省略.........