client.meta.events.register('before-call.s3.PutObject', lf)
e = assert_raises(ClientError, client.put_object, Bucket=bucket_name, Key='foo', Body='bar')
status, error_code = _get_status_and_error_code(e.response)
- assert status == 412
- assert error_code == 'PreconditionFailed'
+ assert status == 404
+ assert error_code == 'NoSuchKey'
e = assert_raises(ClientError, client.get_object, Bucket=bucket_name, Key='foo')
status, error_code = _get_status_and_error_code(e.response)
client.delete_object(Bucket=bucket, Key=key, IfMatch=etag)
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='*')
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='badetag')
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ # -ENOENT doesn't raise error in delete op
+ response = client.delete_object(Bucket=bucket, Key=key, IfMatch='*')
+ assert 204 == response['ResponseMetadata']['HTTPStatusCode']
+ response = client.delete_object(Bucket=bucket, Key=key, IfMatch='badetag')
+ assert 204 == response['ResponseMetadata']['HTTPStatusCode']
# recreate to test IfMatch='*'
client.put_object(Bucket=bucket, Key=key)
check_configure_versioning_retry(bucket, "Enabled", "Enabled")
key = 'obj'
- # on nonexistent object
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='*')
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='badetag')
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ # -ENOENT doesn't raise error in delete op
+ response = client.delete_object(Bucket=bucket, Key=key, IfMatch='*')
+ assert 204 == response['ResponseMetadata']['HTTPStatusCode']
+ response = client.delete_object(Bucket=bucket, Key=key, IfMatch='badetag')
+ assert 204 == response['ResponseMetadata']['HTTPStatusCode']
response = client.put_object(Bucket=bucket, Key=key)
version = response['VersionId']
response = client.delete_object(Bucket=bucket, Key=key, IfMatch=etag)
assert response['DeleteMarker']
- # on current delete marker
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='*')
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ # -ENOENT doesn't raise error in delete op
+ client.delete_object(Bucket=bucket, Key=key, IfMatch='*')
e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatch='badetag')
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
# remove delete marker to retest IfMatch='*'
client.delete_object(Bucket=bucket, Key=key, VersionId=version)
assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatch=etag)
- assert not response['DeleteMarker']
+ assert 'DeleteMarker' not in response
- # on nonexistent version
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatch='*')
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatch='badetag')
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ # -ENOENT doesn't raise error in delete op
+ client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatch='*')
+ client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatch='badetag')
# recreate to test IfMatch='*'
response = client.put_object(Bucket=bucket, Key=key)
client.delete_object(Bucket=bucket, Key=key, IfMatchLastModifiedTime=mtime)
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatchLastModifiedTime=badmtime)
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ response = client.delete_object(Bucket=bucket, Key=key, IfMatchLastModifiedTime=badmtime)
+ assert 204 == response['ResponseMetadata']['HTTPStatusCode']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
response = client.delete_object(Bucket=bucket, Key=key, IfMatchLastModifiedTime=mtime)
assert response['DeleteMarker']
+ # object is marked as deleted but still exists
e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatchLastModifiedTime=badmtime)
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
badmtime = datetime.datetime(2015, 1, 1)
version = client.put_object(Bucket=bucket, Key=key)['VersionId']
- mtime = client.head_object(Bucket=bucket, Key=key)['LastModified']
+ mtime = client.head_object(Bucket=bucket, Key=key, VersionId=version)['LastModified']
e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatchLastModifiedTime=badmtime)
assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatchLastModifiedTime=mtime)
- assert not response['DeleteMarker']
+ assert 'DeleteMarker' not in response
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatchLastModifiedTime=badmtime)
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatchLastModifiedTime=badmtime)
+ assert 204 == response['ResponseMetadata']['HTTPStatusCode']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
client.delete_object(Bucket=bucket, Key=key, IfMatchSize=size)
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatchSize=badsize)
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ response = client.delete_object(Bucket=bucket, Key=key, IfMatchSize=badsize)
+ assert 204 == response['ResponseMetadata']['HTTPStatusCode']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
response = client.delete_object(Bucket=bucket, Key=key, IfMatchSize=size)
- assert response['DeleteMarker']
+ assert 'DeleteMarker' in response
e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, IfMatchSize=badsize)
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
assert (412, 'PreconditionFailed') == _get_status_and_error_code(e.response)
response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatchSize=size)
- assert not response['DeleteMarker']
+ assert 'DeleteMarker' not in response
- e = assert_raises(ClientError, client.delete_object, Bucket=bucket, Key=key, VersionId=version, IfMatchSize=badsize)
- assert (404, 'NoSuchKey') == _get_status_and_error_code(e.response)
+ response = client.delete_object(Bucket=bucket, Key=key, VersionId=version, IfMatchSize=badsize)
+ assert 204 == response['ResponseMetadata']['HTTPStatusCode']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'ETag': etag}]})
assert key == response['Deleted'][0]['Key'] # success
+ # -ENOENT doesn't raise error in delete op
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'ETag': 'badetag'}]})
- assert 'NoSuchKey' == response['Errors'][0]['Code']
+ assert 200 == response['ResponseMetadata']['HTTPStatusCode']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
assert key == response['Deleted'][0]['Key'] # success
assert response['Deleted'][0]['DeleteMarker']
+ # object is marked as deleted but still exists
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'ETag': 'badetag'}]})
- assert 'NoSuchKey' == response['Errors'][0]['Code']
+ assert 'PreconditionFailed' == response['Errors'][0]['Code']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'ETag': etag}]})
assert key == response['Deleted'][0]['Key'] # success
- assert not response['Deleted'][0]['DeleteMarker']
+ assert 'DeleteMarker' not in response['Deleted'][0]
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'ETag': 'badetag'}]})
- assert 'NoSuchKey' == response['Errors'][0]['Code']
+ assert 200 == response['ResponseMetadata']['HTTPStatusCode']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
assert key == response['Deleted'][0]['Key'] # success
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'LastModifiedTime': badmtime}]})
- assert 'NoSuchKey' == response['Errors'][0]['Code']
+ assert 200 == response['ResponseMetadata']['HTTPStatusCode']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
assert key == response['Deleted'][0]['Key'] # success
assert response['Deleted'][0]['DeleteMarker']
+ # object exists, but marked as deleted
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'LastModifiedTime': badmtime}]})
- assert 'NoSuchKey' == response['Errors'][0]['Code']
+ assert 'PreconditionFailed' == response['Errors'][0]['Code']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
badmtime = datetime.datetime(2015, 1, 1)
version = client.put_object(Bucket=bucket, Key=key)['VersionId']
+ mtime = client.head_object(Bucket=bucket, Key=key, VersionId=version)['LastModified']
+
+ # create a different version as current
client.put_object(Bucket=bucket, Key=key)
- mtime = client.head_object(Bucket=bucket, Key=key)['LastModified']
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'LastModifiedTime': badmtime}]})
assert 'PreconditionFailed' == response['Errors'][0]['Code']
assert key == response['Deleted'][0]['Key'] # success
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'LastModifiedTime': badmtime}]})
- assert 'NoSuchKey' == response['Errors'][0]['Code']
+ assert 200 == response['ResponseMetadata']['HTTPStatusCode']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
assert key == response['Deleted'][0]['Key'] # success
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'Size': badsize}]})
- assert 'NoSuchKey' == response['Errors'][0]['Code']
+ assert 200 == response['ResponseMetadata']['HTTPStatusCode']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
assert key == response['Deleted'][0]['Key'] # success
assert response['Deleted'][0]['DeleteMarker']
+ # object exists, but marked as deleted
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'Size': badsize}]})
- assert 'NoSuchKey' == response['Errors'][0]['Code']
+ assert 'PreconditionFailed' == response['Errors'][0]['Code']
@pytest.mark.fails_on_aws # only supported for directory buckets
@pytest.mark.conditional_write
assert key == response['Deleted'][0]['Key'] # success
response = client.delete_objects(Bucket=bucket, Delete={'Objects': [{'Key': key, 'VersionId': version, 'Size': badsize}]})
- assert 'NoSuchKey' == response['Errors'][0]['Code']
+ assert 200 == response['ResponseMetadata']['HTTPStatusCode']