def test_s3_event_notification_with_sqs(self):
    key_by_path = 'aws/bucket=2020/test1.txt'
    bucket_name = ('notif-sqs-%s' % short_uid())
    (queue_url, queue_attributes) = self._create_test_queue()
    self._create_test_notification_bucket(queue_attributes, bucket_name=bucket_name)
    self.s3_client.put_bucket_versioning(Bucket=bucket_name, VersioningConfiguration={'Status': 'Enabled'})
    body = ('Lorem ipsum dolor sit amet, ... ' * 30)
    self.s3_client.put_object(Bucket=bucket_name, Key=key_by_path, Body=body)
    self.assertEqual(self._get_test_queue_message_count(queue_url), '1')
    rs = self.sqs_client.receive_message(QueueUrl=queue_url)
    record = [json.loads(to_str(m['Body'])) for m in rs['Messages']][0]['Records'][0]
    download_file = new_tmp_file()
    self.s3_client.download_file(Bucket=bucket_name, Key=key_by_path, Filename=download_file)
    self.assertEqual(record['s3']['object']['size'], os.path.getsize(download_file))
    self.s3_client.put_bucket_versioning(Bucket=bucket_name, VersioningConfiguration={'Status': 'Disabled'})
    self.sqs_client.delete_queue(QueueUrl=queue_url)
    self._delete_bucket(bucket_name, [key_by_path])
def test_s3_event_notification_with_sqs(self):
    key_by_path = 'aws/bucket=2020/test1.txt'
    bucket_name = ('notif-sqs-%s' % short_uid())
    (queue_url, queue_attributes) = self._create_test_queue()
    self._create_test_notification_bucket(queue_attributes, bucket_name=bucket_name)
    self.s3_client.put_bucket_versioning(Bucket=bucket_name, VersioningConfiguration={'Status': 'Enabled'})
    body = ('Lorem ipsum dolor sit amet, ... ' * 30)
    self.s3_client.put_object(Bucket=bucket_name, Key=key_by_path, Body=body)
    self.assertEqual(self._get_test_queue_message_count(queue_url), '1')
    rs = self.sqs_client.receive_message(QueueUrl=queue_url)
    record = [json.loads(to_str(m['Body'])) for m in rs['Messages']][0]['Records'][0]
    download_file = new_tmp_file()
    self.s3_client.download_file(Bucket=bucket_name, Key=key_by_path, Filename=download_file)
    self.assertEqual(record['s3']['object']['size'], os.path.getsize(download_file))
    self.s3_client.put_bucket_versioning(Bucket=bucket_name, VersioningConfiguration={'Status': 'Disabled'})
    self.sqs_client.delete_queue(QueueUrl=queue_url)
    self._delete_bucket(bucket_name, [key_by_path])