From 0d0527086ca42478d4c068e2690141fc8c68def6 Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Mon, 9 Feb 2015 13:33:19 -0800 Subject: [PATCH 1/3] Fix S3 resource identifier order bug This change fixes the issue described in #59 by updating the model based on the output of the proposed change in awslabs/aws-model-validators#2. The following now works properly: ```python import boto3 obj = boto3.resource('s3').Bucket('foo').Object('bar') mpu = obj.initiate_multipart_upload() part = mpu.MultipartUploadPart(1) print(part.object_key) ``` --- boto3/data/resources/s3-2006-03-01.resources.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/boto3/data/resources/s3-2006-03-01.resources.json b/boto3/data/resources/s3-2006-03-01.resources.json index 508a9a9d87..684caa2b3a 100644 --- a/boto3/data/resources/s3-2006-03-01.resources.json +++ b/boto3/data/resources/s3-2006-03-01.resources.json @@ -698,8 +698,8 @@ "type": "MultipartUploadPart", "identifiers": [ { "target": "BucketName", "source": "identifier", "name": "BucketName" }, - { "target": "MultipartUploadId", "source": "identifier", "name": "Id" }, { "target": "ObjectKey", "source": "identifier", "name": "ObjectKey" }, + { "target": "MultipartUploadId", "source": "identifier", "name": "Id" }, { "target": "PartNumber", "source": "input" } ] } @@ -770,8 +770,8 @@ "type": "MultipartUpload", "identifiers": [ { "target": "BucketName", "source": "identifier", "name": "BucketName" }, - { "target": "Id", "source": "identifier", "name": "MultipartUploadId" }, - { "target": "ObjectKey", "source": "identifier", "name": "ObjectKey" } + { "target": "ObjectKey", "source": "identifier", "name": "ObjectKey" }, + { "target": "Id", "source": "identifier", "name": "MultipartUploadId" } ] } } From aaab03ed94ae5948b91005a730353b335a77c692 Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Tue, 10 Feb 2015 11:49:34 -0800 Subject: [PATCH 2/3] Add integration test --- tests/integration/test_s3.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/integration/test_s3.py b/tests/integration/test_s3.py index affb800c29..bef330aab1 100644 --- a/tests/integration/test_s3.py +++ b/tests/integration/test_s3.py @@ -92,3 +92,29 @@ def test_can_create_object_directly(self): self.assertEqual(obj.bucket_name, self.bucket_name) self.assertEqual(obj.key, 'test.txt') + + def test_s3_multipart(self): + # Create the bucket + bucket = self.create_bucket_resource(self.bucket_name) + bucket.wait_until_exists() + + # Create the multipart upload + mpu = bucket.Object('mp-test.txt').initiate_multipart_upload() + self.addCleanup(mpu.abort) + + # Create and upload a part + part = mpu.Part(1) + response = part.upload(b'hello, world!') + + # Complete the upload, which requires info on all of the parts + part_info = { + 'Parts': [ + { + 'PartNumber': 1, + 'ETag': response['ETag'] + } + ] + } + + mpu.complete(MultipartUpload=part_info) + self.addCleanup(bucket.Object('mp-test.txt').delete) From df4d95b1d6c28248cf31e5a72ead54f6dc56f02b Mon Sep 17 00:00:00 2001 From: "Daniel G. Taylor" Date: Tue, 10 Feb 2015 13:00:27 -0800 Subject: [PATCH 3/3] Add assertion to test --- tests/integration/test_s3.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_s3.py b/tests/integration/test_s3.py index bef330aab1..ef4ac3b057 100644 --- a/tests/integration/test_s3.py +++ b/tests/integration/test_s3.py @@ -104,7 +104,7 @@ def test_s3_multipart(self): # Create and upload a part part = mpu.Part(1) - response = part.upload(b'hello, world!') + response = part.upload(Body='hello, world!') # Complete the upload, which requires info on all of the parts part_info = { @@ -118,3 +118,6 @@ def test_s3_multipart(self): mpu.complete(MultipartUpload=part_info) self.addCleanup(bucket.Object('mp-test.txt').delete) + + contents = bucket.Object('mp-test.txt').get()['Body'].read() + self.assertEqual(contents, b'hello, world!')