def test_s3_put_object_notification(self):
    bucket_name = ('notif-%s' % short_uid())
    key_by_path = 'key-by-hostname'
    key_by_host = 'key-by-host'
    (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'})
    obj = self.s3_client.put_object(Bucket=bucket_name, Key=key_by_path, Body='something')
    headers = {'Host': '{}.s3.amazonaws.com'.format(bucket_name), 'authorization': 'some_token'}
    url = '{}/{}'.format(config.TEST_S3_URL, key_by_host)
    response = requests.put(url, data='something else', headers=headers, verify=False)
    self.assertTrue(response.ok)
    self.assertEqual(self._get_test_queue_message_count(queue_url), '2')
    response = self.sqs_client.receive_message(QueueUrl=queue_url)
    messages = [json.loads(to_str(m['Body'])) for m in response['Messages']]
    record = messages[0]['Records'][0]
    self.assertIsNotNone(record['s3']['object']['versionId'])
    self.assertEquals(record['s3']['object']['versionId'], obj['VersionId'])
    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, key_by_host])
def test_s3_put_object_notification(self):
    bucket_name = ('notif-%s' % short_uid())
    key_by_path = 'key-by-hostname'
    key_by_host = 'key-by-host'
    (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'})
    obj = self.s3_client.put_object(Bucket=bucket_name, Key=key_by_path, Body='something')
    headers = {'Host': '{}.s3.amazonaws.com'.format(bucket_name), 'authorization': 'some_token'}
    url = '{}/{}'.format(config.TEST_S3_URL, key_by_host)
    response = requests.put(url, data='something else', headers=headers, verify=False)
    self.assertTrue(response.ok)
    self.assertEqual(self._get_test_queue_message_count(queue_url), '2')
    response = self.sqs_client.receive_message(QueueUrl=queue_url)
    messages = [json.loads(to_str(m['Body'])) for m in response['Messages']]
    record = messages[0]['Records'][0]
    self.assertIsNotNone(record['s3']['object']['versionId'])
    self.assertEquals(record['s3']['object']['versionId'], obj['VersionId'])
    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, key_by_host])