Skip to content

Commit cfb361a

Browse files
authored
Merge pull request #693 from AliMasarweh/wip-s3-conditional-write
s3: test conditional multipart_put_object()
2 parents 4e55e7b + 3ebf3ec commit cfb361a

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed

s3tests_boto3/functional/test_s3.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18680,6 +18680,69 @@ def test_put_object_if_match():
1868018680
response = client.put_object(Bucket=bucket, Key=key, IfMatch=etag)
1868118681
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
1868218682

18683+
def prepare_multipart_upload(client, bucket, key, body):
18684+
upload_id = client.create_multipart_upload(Bucket=bucket, Key=key)['UploadId']
18685+
response = client.upload_part(UploadId=upload_id, Bucket=bucket, Key=key, PartNumber=1, Body=body)
18686+
parts = [{'ETag': response['ETag'].strip('"'), 'PartNumber': 1}]
18687+
return upload_id, parts
18688+
18689+
def successful_conditional_multipart_upload(client, bucket, key, body='abc', IfMatch=None, IfNoneMatch=None):
18690+
upload_id, parts = prepare_multipart_upload(client, bucket, key, body)
18691+
if IfMatch:
18692+
response = client.complete_multipart_upload(Bucket=bucket, Key=key, IfMatch=IfMatch, UploadId=upload_id, MultipartUpload={'Parts': parts})
18693+
elif IfNoneMatch :
18694+
response = client.complete_multipart_upload(Bucket=bucket, Key=key, IfNoneMatch=IfNoneMatch, UploadId=upload_id, MultipartUpload={'Parts': parts})
18695+
else :
18696+
response = client.complete_multipart_upload(Bucket=bucket, Key=key, UploadId=upload_id, MultipartUpload={'Parts': parts})
18697+
18698+
return response
18699+
18700+
def failing_conditional_multipart_upload(expected_failure, client, bucket, key, body='abc', IfMatch=None, IfNoneMatch=None):
18701+
upload_id, parts = prepare_multipart_upload(client, bucket, key, body)
18702+
if IfMatch:
18703+
e = assert_raises(ClientError, client.complete_multipart_upload, Bucket=bucket, Key=key, IfMatch=IfMatch, UploadId=upload_id, MultipartUpload={'Parts': parts})
18704+
elif IfNoneMatch:
18705+
e = assert_raises(ClientError, client.complete_multipart_upload, Bucket=bucket, Key=key, IfNoneMatch=IfNoneMatch, UploadId=upload_id, MultipartUpload={'Parts': parts})
18706+
else :
18707+
e = assert_raises(ClientError, client.complete_multipart_upload, Bucket=bucket, Key=key, UploadId=upload_id, MultipartUpload={'Parts': parts})
18708+
18709+
assert expected_failure == _get_status_and_error_code(e.response)
18710+
18711+
@pytest.mark.conditional_write
18712+
@pytest.mark.fails_on_dbstore
18713+
def test_multipart_put_object_if_match():
18714+
client = get_client()
18715+
bucket = get_new_bucket(client)
18716+
key = 'obj'
18717+
18718+
response = successful_conditional_multipart_upload(client, bucket, key, IfNoneMatch='*')
18719+
etag = response['ETag']
18720+
18721+
failing_conditional_multipart_upload((412, 'PreconditionFailed'), client, bucket, key, IfNoneMatch='*')
18722+
failing_conditional_multipart_upload((412, 'PreconditionFailed'), client, bucket, key, IfNoneMatch=etag)
18723+
18724+
response = successful_conditional_multipart_upload(client, bucket, key, IfNoneMatch='badetag')
18725+
etag = response['ETag']
18726+
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
18727+
18728+
response = successful_conditional_multipart_upload(client, bucket, key, IfMatch=etag)
18729+
etag = response['ETag']
18730+
18731+
client.delete_object(Bucket=bucket, Key=key)
18732+
18733+
failing_conditional_multipart_upload((404, 'NoSuchKey'), client, bucket, key, IfMatch='*')
18734+
failing_conditional_multipart_upload((404, 'NoSuchKey'), client, bucket, key, IfMatch='badetag')
18735+
18736+
response = successful_conditional_multipart_upload(client, bucket, key, IfNoneMatch=etag)
18737+
etag = response['ETag']
18738+
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
18739+
response = successful_conditional_multipart_upload(client, bucket, key, IfMatch='*')
18740+
etag = response['ETag']
18741+
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
18742+
failing_conditional_multipart_upload((412, 'PreconditionFailed'), client, bucket, key, IfMatch='badetag')
18743+
response = successful_conditional_multipart_upload(client, bucket, key, IfMatch=etag)
18744+
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
18745+
1868318746
@pytest.mark.conditional_write
1868418747
@pytest.mark.fails_on_dbstore
1868518748
def test_put_current_object_if_none_match():
@@ -18709,6 +18772,33 @@ def test_put_current_object_if_none_match():
1870918772

1871018773
client.delete_object(Bucket=bucket, Key=key)
1871118774

18775+
@pytest.mark.conditional_write
18776+
@pytest.mark.fails_on_dbstore
18777+
def test_multipart_put_current_object_if_none_match():
18778+
client = get_client()
18779+
bucket = get_new_bucket(client)
18780+
check_configure_versioning_retry(bucket, "Enabled", "Enabled")
18781+
key = 'obj'
18782+
data1 = 'data1'
18783+
data2 = 'data2'
18784+
18785+
response = successful_conditional_multipart_upload(client, bucket, key, data1, IfNoneMatch='*')
18786+
etag = response['ETag']
18787+
18788+
response = successful_conditional_multipart_upload(client, bucket, key, data2)
18789+
etag2 = response['ETag']
18790+
18791+
failing_conditional_multipart_upload((412, 'PreconditionFailed'), client, bucket, key, IfNoneMatch='*')
18792+
failing_conditional_multipart_upload((412, 'PreconditionFailed'), client, bucket, key, IfNoneMatch=etag2)
18793+
18794+
# we can't specify a version, so we only check against current object
18795+
response = successful_conditional_multipart_upload(client, bucket, key, IfNoneMatch=etag)
18796+
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
18797+
response = successful_conditional_multipart_upload(client, bucket, key, IfNoneMatch='badetag')
18798+
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
18799+
18800+
client.delete_object(Bucket=bucket, Key=key)
18801+
1871218802
@pytest.mark.conditional_write
1871318803
@pytest.mark.fails_on_dbstore
1871418804
def test_put_current_object_if_match():
@@ -18740,6 +18830,33 @@ def test_put_current_object_if_match():
1874018830
response = client.put_object(Bucket=bucket, Key=key, IfMatch=etag2)
1874118831
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
1874218832

18833+
@pytest.mark.conditional_write
18834+
@pytest.mark.fails_on_dbstore
18835+
def test_multipart_put_current_object_if_match():
18836+
client = get_client()
18837+
bucket = get_new_bucket(client)
18838+
check_configure_versioning_retry(bucket, "Enabled", "Enabled")
18839+
key = 'obj'
18840+
data1 = 'data1'
18841+
data2 = 'data2'
18842+
etag = 'deadbeef'
18843+
18844+
failing_conditional_multipart_upload((404, 'NoSuchKey'), client, bucket, key, IfMatch='*')
18845+
failing_conditional_multipart_upload((404, 'NoSuchKey'), client, bucket, key, IfMatch='badetag')
18846+
18847+
response = successful_conditional_multipart_upload(client, bucket, key, data1, IfNoneMatch=etag)
18848+
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
18849+
etag = response['ETag']
18850+
versionId = response['VersionId']
18851+
response = successful_conditional_multipart_upload(client, bucket, key, data2, IfMatch='*')
18852+
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
18853+
etag2 = response['ETag']
18854+
18855+
failing_conditional_multipart_upload((412, 'PreconditionFailed'), client, bucket, key, IfMatch='badetag')
18856+
failing_conditional_multipart_upload((412, 'PreconditionFailed'), client, bucket, key, IfMatch=etag)
18857+
response = successful_conditional_multipart_upload(client, bucket, key, IfMatch=etag2)
18858+
assert 200 == response['ResponseMetadata']['HTTPStatusCode']
18859+
1874318860
@pytest.mark.conditional_write
1874418861
@pytest.mark.fails_on_dbstore
1874518862
def test_put_object_current_if_match():

0 commit comments

Comments
 (0)