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()
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()
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) m.get('https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>' + lpath + '</Name>' '<Properties><Content-Length>6</Content-Length>' '<Content-MD5>md5</Content-MD5><BlobType>BlockBlob</BlobType>' '</Properties></Blob></Blobs></EnumerationResults>') args.progressbar = False args.keeprootdir = False args.skiponmatch = True blobxfer.main() args.progressbar = True args.download = True args.upload = False args.remoteresource = 'blob' args.localresource = str(tmpdir) m.head('https://blobep.blobep/container/blob?saskey', headers={ 'content-length': '6', 'content-md5': '1qmpM8iq/FHlWsBmK25NSg=='}) m.get('https://blobep.blobep/container/blob?saskey', content=b'012345') blobxfer.main() args.remoteresource = '.' args.keepmismatchedmd5files = False m.get('https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '</Blob></Blobs></EnumerationResults>') m.get('https://blobep.blobep/container/?saskey') with pytest.raises(SystemExit): blobxfer.main() m.get('https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>md5' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '</Blob></Blobs></EnumerationResults>') blobxfer.main() tmplpath = str(tmpdir.join('test', 'test2', 'test3')) print(tmplpath) args.localresource = tmplpath blobxfer.main() args.localresource = str(tmpdir) notmp_lpath = '/'.join(lpath.strip('/').split('/')[1:]) with requests_mock.mock() as m: args.download = False args.upload = True args.remoteresource = None args.skiponmatch = False m.put('https://blobep.blobep/container/test.tmp?saskey' '&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/test.tmp?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=blocklist', status_code=201) with pytest.raises(SystemExit): blobxfer.main() args.recursive = False m.put('https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/test.tmp.blobtmp?saskey' '&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/blob?saskey&comp=blocklist', status_code=201) with pytest.raises(SystemExit): blobxfer.main() args.pageblob = True args.upload = True args.download = False m.put('https://blobep.blobep/container/blob.blobtmp?saskey', status_code=201) m.put('https://blobep.blobep/container/test.tmp?saskey', status_code=201) m.put('https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=properties', status_code=200) m.put('https://blobep.blobep/container/test.tmp?saskey' '&comp=properties', status_code=200) m.put('https://blobep.blobep/container/blob?saskey', status_code=201) with pytest.raises(IOError): blobxfer.main() m.put('https://blobep.blobep/container/blobsaskey', status_code=200) with pytest.raises(IOError): blobxfer.main() m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/blob?saskey', status_code=201) args.pageblob = False blobxfer.main() args.pageblob = False args.autovhd = True blobxfer.main()
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): blobxfer.main() args.saskey = None with pytest.raises(ValueError): blobxfer.main() args.managementcert = '0' args.managementep = '' args.subscriptionid = '0' with pytest.raises(ValueError): blobxfer.main() args.managementcert = 'test.pem' with pytest.raises(ValueError): blobxfer.main() args.managementep = 'mep.mep' ssk = MagicMock() ssk.storage_service_keys = MagicMock() ssk.storage_service_keys.primary = '' patched_sms_sakeys.return_value = ssk ssp = MagicMock() ssp.storage_service_properties = MagicMock() ssp.storage_service_properties.endpoints = ['blobep'] patched_sms_saprops.return_value = ssp with pytest.raises(ValueError): blobxfer.main() ssk.storage_service_keys.primary = 'key1' args.storageaccountkey = None args.rsaprivatekey = '' args.rsapublickey = '' with pytest.raises(ValueError): blobxfer.main() args.rsaprivatekey = '' args.rsapublickey = None args.encmode = blobxfer._ENCRYPTION_MODE_FULLBLOB with pytest.raises(IOError): blobxfer.main() args.rsaprivatekey = None args.storageaccountkey = None args.managementcert = None args.managementep = None args.subscriptionid = 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) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=block&blockid=00000000', status_code=201) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=metadata', status_code=200) m.get('https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>' + lpath + '</Name>' '<Properties><Content-Length>6</Content-Length>' '<Content-MD5>md5</Content-MD5><BlobType>BlockBlob</BlobType>' '</Properties><Metadata/></Blob></Blobs></EnumerationResults>') args.progressbar = False args.skiponmatch = True blobxfer.main() args.progressbar = True args.download = True args.upload = False args.remoteresource = None with pytest.raises(ValueError): blobxfer.main() args.remoteresource = 'blob' args.localresource = str(tmpdir) m.head('https://blobep.blobep/container/blob?saskey', headers={ 'content-length': '6', 'content-md5': '1qmpM8iq/FHlWsBmK25NSg=='}) m.get('https://blobep.blobep/container/blob?saskey', content=b'012345') blobxfer.main() args.pageblob = False args.autovhd = False args.skiponmatch = False pemcontents = _RSAKEY.private_bytes( encoding=cryptography.hazmat.primitives.serialization. Encoding.PEM, format=cryptography.hazmat.primitives.serialization. PrivateFormat.PKCS8, encryption_algorithm=cryptography.hazmat.primitives. serialization.NoEncryption()) pempath = str(tmpdir.join('rsa.pem')) with open(pempath, 'wb') as f: f.write(pemcontents) args.rsaprivatekey = pempath blobxfer.main() os.remove(pempath) args.rsaprivatekey = None args.skiponmatch = True args.remoteresource = '.' args.keepmismatchedmd5files = False m.get('https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '<Metadata/></Blob></Blobs></EnumerationResults>') m.get('https://blobep.blobep/container/?saskey') with pytest.raises(SystemExit): blobxfer.main() m.get('https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>md5' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '<Metadata/></Blob></Blobs></EnumerationResults>') blobxfer.main() tmplpath = str(tmpdir.join('test', 'test2', 'test3')) args.localresource = tmplpath blobxfer.main() args.localresource = str(tmpdir) notmp_lpath = '/'.join(lpath.strip('/').split('/')[1:]) with requests_mock.mock() as m: args.delete = True args.download = False args.upload = True args.remoteresource = None args.skiponmatch = False m.put('https://blobep.blobep/container/test.tmp?saskey' '&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/test.tmp?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=blocklist', status_code=201) m.get('https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>md5' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '<Metadata/></Blob></Blobs></EnumerationResults>') m.delete('https://blobep.blobep/container/blob?saskey', status_code=202) with pytest.raises(SystemExit): blobxfer.main() args.recursive = False m.put('https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/test.tmp.blobtmp?saskey' '&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/blob?saskey&comp=blocklist', status_code=201) with pytest.raises(SystemExit): blobxfer.main() args.stripcomponents = None args.collate = '.' args.pageblob = True args.upload = True args.download = False m.put('https://blobep.blobep/container/blob.blobtmp?saskey', status_code=201) m.put('https://blobep.blobep/container/test.tmp?saskey', status_code=201) m.put('https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=properties', status_code=200) m.put('https://blobep.blobep/container/test.tmp?saskey' '&comp=properties', status_code=200) m.put('https://blobep.blobep/container/blob?saskey', status_code=201) with pytest.raises(IOError): blobxfer.main() args.stripcomponents = None m.put('https://blobep.blobep/container/blobsaskey', status_code=200) with pytest.raises(IOError): blobxfer.main() args.stripcomponents = None args.pageblob = False m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/blob?saskey', status_code=201) blobxfer.main() args.stripcomponents = None args.autovhd = True blobxfer.main() args.stripcomponents = None args.include = 'nofiles' with pytest.raises(SystemExit): blobxfer.main() args.stripcomponents = None args.include = '*' blobxfer.main() args.include = None args.stripcomponents = None args.pageblob = False args.autovhd = False pempath = str(tmpdir.join('rsa.pem')) with open(pempath, 'wb') as f: f.write(pemcontents) args.rsaprivatekey = pempath m.put('https://blobep.blobep/container/rsa.pem?saskey&comp=block' '&blockid=00000000', status_code=201) m.put('https://blobep.blobep/container/rsa.pem?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/rsa.pem?saskey&comp=metadata', status_code=200) m.put('https://blobep.blobep/container/blob?saskey&comp=metadata', status_code=200) m.put('https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=metadata', status_code=200) m.put('https://blobep.blobep/container/test.tmp.blobtmp?saskey' '&comp=metadata', status_code=200) m.put('https://blobep.blobep/container/test.tmp?saskey&comp=metadata', status_code=200) blobxfer.main() args.stripcomponents = None args.download = True args.upload = False args.rsaprivatekey = pempath args.remoteresource = 'blob' args.localresource = str(tmpdir) m.head('https://blobep.blobep/container/blob?saskey', headers={ 'content-length': '6', 'content-md5': '1qmpM8iq/FHlWsBmK25NSg=='}) m.get('https://blobep.blobep/container/blob?saskey', content=b'012345') # TODO add encrypted data json blobxfer.main()
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) m.get( 'https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>' + lpath + '</Name>' '<Properties><Content-Length>6</Content-Length>' '<Content-MD5>md5</Content-MD5><BlobType>BlockBlob</BlobType>' '</Properties></Blob></Blobs></EnumerationResults>') args.progressbar = False args.keeprootdir = False args.skiponmatch = True blobxfer.main() args.progressbar = True args.download = True args.upload = False args.remoteresource = 'blob' args.localresource = str(tmpdir) m.head('https://blobep.blobep/container/blob?saskey', headers={ 'content-length': '6', 'content-md5': '1qmpM8iq/FHlWsBmK25NSg==' }) m.get('https://blobep.blobep/container/blob?saskey', content=b'012345') blobxfer.main() args.remoteresource = '.' args.keepmismatchedmd5files = False m.get( 'https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '</Blob></Blobs></EnumerationResults>') m.get('https://blobep.blobep/container/?saskey') with pytest.raises(SystemExit): blobxfer.main() m.get( 'https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>md5' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '</Blob></Blobs></EnumerationResults>') blobxfer.main() tmplpath = str(tmpdir.join('test', 'test2', 'test3')) print(tmplpath) args.localresource = tmplpath blobxfer.main() args.localresource = str(tmpdir) notmp_lpath = '/'.join(lpath.strip('/').split('/')[1:]) with requests_mock.mock() as m: args.download = False args.upload = True args.remoteresource = None args.skiponmatch = False m.put( 'https://blobep.blobep/container/test.tmp?saskey' '&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/test.tmp?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=blocklist', status_code=201) with pytest.raises(SystemExit): blobxfer.main() args.recursive = False m.put( 'https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=blocklist', status_code=201) m.put( 'https://blobep.blobep/container/test.tmp.blobtmp?saskey' '&comp=blocklist', status_code=201) m.put( 'https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/blob?saskey&comp=blocklist', status_code=201) with pytest.raises(SystemExit): blobxfer.main() args.pageblob = True args.upload = True args.download = False m.put('https://blobep.blobep/container/blob.blobtmp?saskey', status_code=201) m.put('https://blobep.blobep/container/test.tmp?saskey', status_code=201) m.put( 'https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=properties', status_code=200) m.put( 'https://blobep.blobep/container/test.tmp?saskey' '&comp=properties', status_code=200) m.put('https://blobep.blobep/container/blob?saskey', status_code=201) with pytest.raises(IOError): blobxfer.main() m.put('https://blobep.blobep/container/blobsaskey', status_code=200) with pytest.raises(IOError): blobxfer.main() m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/blob?saskey', status_code=201) args.pageblob = False blobxfer.main() args.pageblob = False args.autovhd = True blobxfer.main()
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 = "" args.subscriptionid = "0" with pytest.raises(ValueError): blobxfer.main() args.managementcert = "test.pem" with pytest.raises(ValueError): blobxfer.main() args.managementep = "mep.mep" ssk = MagicMock() ssk.storage_service_keys = MagicMock() ssk.storage_service_keys.primary = "" patched_sms_sakeys.return_value = ssk ssp = MagicMock() ssp.storage_service_properties = MagicMock() ssp.storage_service_properties.endpoints = ["blobep"] patched_sms_saprops.return_value = ssp with pytest.raises(ValueError): blobxfer.main() ssk.storage_service_keys.primary = "key1" args.storageaccountkey = None with pytest.raises(Exception): blobxfer.main() args.storageaccountkey = None args.managementcert = None args.managementep = None args.subscriptionid = 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) m.put("https://blobep.blobep/container" + lpath + "?saskey&comp=block&blockid=00000000", status_code=201) m.get( "https://blobep.blobep/container?saskey&comp=list" "&restype=container&maxresults=1000", text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>' + lpath + "</Name>" "<Properties><Content-Length>6</Content-Length>" "<Content-MD5>md5</Content-MD5><BlobType>BlockBlob</BlobType>" "</Properties></Blob></Blobs></EnumerationResults>", ) args.progressbar = False args.keeprootdir = False args.skiponmatch = True blobxfer.main() args.progressbar = True args.download = True args.upload = False args.remoteresource = None with pytest.raises(ValueError): blobxfer.main() args.remoteresource = "blob" args.localresource = str(tmpdir) m.head( "https://blobep.blobep/container/blob?saskey", headers={"content-length": "6", "content-md5": "1qmpM8iq/FHlWsBmK25NSg=="}, ) m.get("https://blobep.blobep/container/blob?saskey", content=b"012345") blobxfer.main() args.remoteresource = "." args.keepmismatchedmd5files = False m.get( "https://blobep.blobep/container?saskey&comp=list" "&restype=container&maxresults=1000", text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' "<Content-Length>6</Content-Length><Content-MD5>" "</Content-MD5><BlobType>BlockBlob</BlobType></Properties>" "</Blob></Blobs></EnumerationResults>", ) m.get("https://blobep.blobep/container/?saskey") with pytest.raises(SystemExit): blobxfer.main() m.get( "https://blobep.blobep/container?saskey&comp=list" "&restype=container&maxresults=1000", text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' "<Content-Length>6</Content-Length><Content-MD5>md5" "</Content-MD5><BlobType>BlockBlob</BlobType></Properties>" "</Blob></Blobs></EnumerationResults>", ) blobxfer.main() tmplpath = str(tmpdir.join("test", "test2", "test3")) print(tmplpath) args.localresource = tmplpath blobxfer.main() args.localresource = str(tmpdir) notmp_lpath = "/".join(lpath.strip("/").split("/")[1:]) with requests_mock.mock() as m: args.download = False args.upload = True args.remoteresource = None args.skiponmatch = False m.put("https://blobep.blobep/container/test.tmp?saskey" "&comp=block&blockid=00000000", status_code=200) m.put("https://blobep.blobep/container/test.tmp?saskey&comp=blocklist", status_code=201) m.put("https://blobep.blobep/container" + lpath + "?saskey&comp=block&blockid=00000000", status_code=200) m.put("https://blobep.blobep/container" + lpath + "?saskey&comp=blocklist", status_code=201) m.put("https://blobep.blobep/container/" + notmp_lpath + "?saskey&comp=block&blockid=00000000", status_code=200) m.put("https://blobep.blobep/container/" + notmp_lpath + "?saskey&comp=blocklist", status_code=201) with pytest.raises(SystemExit): blobxfer.main() args.recursive = False m.put("https://blobep.blobep/container/blob.blobtmp?saskey" "&comp=blocklist", status_code=201) m.put("https://blobep.blobep/container/test.tmp.blobtmp?saskey" "&comp=blocklist", status_code=201) m.put("https://blobep.blobep/container/blob.blobtmp?saskey" "&comp=block&blockid=00000000", status_code=200) m.put("https://blobep.blobep/container/blob?saskey&comp=blocklist", status_code=201) with pytest.raises(SystemExit): blobxfer.main() args.pageblob = True args.upload = True args.download = False m.put("https://blobep.blobep/container/blob.blobtmp?saskey", status_code=201) m.put("https://blobep.blobep/container/test.tmp?saskey", status_code=201) m.put("https://blobep.blobep/container/blob.blobtmp?saskey" "&comp=properties", status_code=200) m.put("https://blobep.blobep/container/test.tmp?saskey" "&comp=properties", status_code=200) m.put("https://blobep.blobep/container/blob?saskey", status_code=201) with pytest.raises(IOError): blobxfer.main() m.put("https://blobep.blobep/container/blobsaskey", status_code=200) with pytest.raises(IOError): blobxfer.main() m.put("https://blobep.blobep/container/" + notmp_lpath + "?saskey&comp=blocklist", status_code=201) m.put("https://blobep.blobep/container/blob?saskey", status_code=201) args.pageblob = False blobxfer.main() args.pageblob = False args.autovhd = True blobxfer.main()
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): blobxfer.main() args.saskey = None with pytest.raises(ValueError): blobxfer.main() args.managementcert = '0' args.managementep = '' args.subscriptionid = '0' with pytest.raises(ValueError): blobxfer.main() args.managementcert = 'test.pem' with pytest.raises(ValueError): blobxfer.main() args.managementep = 'mep.mep' ssk = MagicMock() ssk.storage_service_keys = MagicMock() ssk.storage_service_keys.primary = '' patched_sms_sakeys.return_value = ssk ssp = MagicMock() ssp.storage_service_properties = MagicMock() ssp.storage_service_properties.endpoints = ['blobep'] patched_sms_saprops.return_value = ssp with pytest.raises(ValueError): blobxfer.main() ssk.storage_service_keys.primary = 'key1' args.storageaccountkey = None args.rsaprivatekey = '' args.rsapublickey = '' with pytest.raises(ValueError): blobxfer.main() args.rsaprivatekey = '' args.rsapublickey = None args.encmode = blobxfer._ENCRYPTION_MODE_FULLBLOB with pytest.raises(IOError): blobxfer.main() args.rsaprivatekey = None args.storageaccountkey = None args.managementcert = None args.managementep = None args.subscriptionid = 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) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=block&blockid=00000000', status_code=201) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=metadata', status_code=200) m.get( 'https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>' + lpath + '</Name>' '<Properties><Content-Length>6</Content-Length>' '<Content-MD5>md5</Content-MD5><BlobType>BlockBlob</BlobType>' '</Properties><Metadata/></Blob></Blobs></EnumerationResults>') args.progressbar = False args.skiponmatch = True blobxfer.main() args.progressbar = True args.download = True args.upload = False args.remoteresource = None with pytest.raises(ValueError): blobxfer.main() args.remoteresource = 'blob' args.localresource = str(tmpdir) m.head('https://blobep.blobep/container/blob?saskey', headers={ 'content-length': '6', 'content-md5': '1qmpM8iq/FHlWsBmK25NSg==' }) m.get('https://blobep.blobep/container/blob?saskey', content=b'012345') blobxfer.main() args.pageblob = False args.autovhd = False args.skiponmatch = False pemcontents = _RSAKEY.private_bytes( encoding=cryptography.hazmat.primitives.serialization.Encoding.PEM, format=cryptography.hazmat.primitives.serialization.PrivateFormat. PKCS8, encryption_algorithm=cryptography.hazmat.primitives.serialization. NoEncryption()) pempath = str(tmpdir.join('rsa.pem')) with open(pempath, 'wb') as f: f.write(pemcontents) args.rsaprivatekey = pempath blobxfer.main() os.remove(pempath) args.rsaprivatekey = None args.skiponmatch = True args.remoteresource = '.' args.keepmismatchedmd5files = False m.get( 'https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '<Metadata/></Blob></Blobs></EnumerationResults>') m.get('https://blobep.blobep/container/?saskey') with pytest.raises(SystemExit): blobxfer.main() m.get( 'https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>md5' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '<Metadata/></Blob></Blobs></EnumerationResults>') blobxfer.main() tmplpath = str(tmpdir.join('test', 'test2', 'test3')) args.localresource = tmplpath blobxfer.main() args.localresource = str(tmpdir) notmp_lpath = '/'.join(lpath.strip('/').split('/')[1:]) with requests_mock.mock() as m: args.delete = True args.download = False args.upload = True args.remoteresource = None args.skiponmatch = False m.put( 'https://blobep.blobep/container/test.tmp?saskey' '&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/test.tmp?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container' + lpath + '?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=blocklist', status_code=201) m.get( 'https://blobep.blobep/container?saskey&comp=list' '&restype=container&maxresults=1000', text='<?xml version="1.0" encoding="utf-8"?>' '<EnumerationResults ContainerName="https://blobep.blobep/' 'container"><Blobs><Blob><Name>blob</Name><Properties>' '<Content-Length>6</Content-Length><Content-MD5>md5' '</Content-MD5><BlobType>BlockBlob</BlobType></Properties>' '<Metadata/></Blob></Blobs></EnumerationResults>') m.delete('https://blobep.blobep/container/blob?saskey', status_code=202) with pytest.raises(SystemExit): blobxfer.main() args.recursive = False m.put( 'https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=blocklist', status_code=201) m.put( 'https://blobep.blobep/container/test.tmp.blobtmp?saskey' '&comp=blocklist', status_code=201) m.put( 'https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=block&blockid=00000000', status_code=200) m.put('https://blobep.blobep/container/blob?saskey&comp=blocklist', status_code=201) with pytest.raises(SystemExit): blobxfer.main() args.stripcomponents = None args.collate = '.' args.pageblob = True args.upload = True args.download = False m.put('https://blobep.blobep/container/blob.blobtmp?saskey', status_code=201) m.put('https://blobep.blobep/container/test.tmp?saskey', status_code=201) m.put( 'https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=properties', status_code=200) m.put( 'https://blobep.blobep/container/test.tmp?saskey' '&comp=properties', status_code=200) m.put('https://blobep.blobep/container/blob?saskey', status_code=201) with pytest.raises(IOError): blobxfer.main() args.stripcomponents = None m.put('https://blobep.blobep/container/blobsaskey', status_code=200) with pytest.raises(IOError): blobxfer.main() args.stripcomponents = None args.pageblob = False m.put('https://blobep.blobep/container/' + notmp_lpath + '?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/blob?saskey', status_code=201) blobxfer.main() args.stripcomponents = None args.autovhd = True blobxfer.main() args.stripcomponents = None args.include = 'nofiles' with pytest.raises(SystemExit): blobxfer.main() args.stripcomponents = None args.include = '*' blobxfer.main() args.include = None args.stripcomponents = None args.pageblob = False args.autovhd = False pempath = str(tmpdir.join('rsa.pem')) with open(pempath, 'wb') as f: f.write(pemcontents) args.rsaprivatekey = pempath m.put( 'https://blobep.blobep/container/rsa.pem?saskey&comp=block' '&blockid=00000000', status_code=201) m.put('https://blobep.blobep/container/rsa.pem?saskey&comp=blocklist', status_code=201) m.put('https://blobep.blobep/container/rsa.pem?saskey&comp=metadata', status_code=200) m.put('https://blobep.blobep/container/blob?saskey&comp=metadata', status_code=200) m.put( 'https://blobep.blobep/container/blob.blobtmp?saskey' '&comp=metadata', status_code=200) m.put( 'https://blobep.blobep/container/test.tmp.blobtmp?saskey' '&comp=metadata', status_code=200) m.put('https://blobep.blobep/container/test.tmp?saskey&comp=metadata', status_code=200) blobxfer.main() args.stripcomponents = None args.download = True args.upload = False args.rsaprivatekey = pempath args.remoteresource = 'blob' args.localresource = str(tmpdir) m.head('https://blobep.blobep/container/blob?saskey', headers={ 'content-length': '6', 'content-md5': '1qmpM8iq/FHlWsBmK25NSg==' }) m.get('https://blobep.blobep/container/blob?saskey', content=b'012345') # TODO add encrypted data json blobxfer.main()