Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_stubbed_responses(self):
return [
{
'method': 'head_object',
'service_response': {
'ContentLength': len(self.content)
}
},
{
'method': 'get_object',
'service_response': {
'Body': six.BytesIO(self.content[0:4])
}
},
{
'method': 'get_object',
'service_response': {
'Body': six.BytesIO(self.content[4:8])
}
},
{
'method': 'get_object',
'service_response': {
'Body': six.BytesIO(self.content[8:])
}
def test_download_empty_object(self):
self.content = b''
self.stream = six.BytesIO(self.content)
self.add_head_object_response()
self.add_successful_get_object_responses()
future = self.manager.download(
self.bucket, self.key, self.filename, self.extra_args)
future.result()
# Ensure that the empty file exists
with open(self.filename, 'rb') as f:
self.assertEqual(b'', f.read())
def add_get_responses(self):
chunksize = self.config.multipart_chunksize
for i in range(0, len(self.content), chunksize):
if i + chunksize > len(self.content):
stream = six.BytesIO(self.content[i:])
self.stubber.add_response('get_object', {'Body': stream})
else:
stream = six.BytesIO(self.content[i:i+chunksize])
self.stubber.add_response('get_object', {'Body': stream})