From f17d5f8e4d14d36fb662eb360f10158a78df8a0c Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Tue, 10 Mar 2020 12:56:33 +0000 Subject: [PATCH 1/2] #657 - S3 - Verify content type is set/returned as appropriate --- tests/test_s3/test_s3.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 48655ee17..48939be26 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -11,6 +11,7 @@ from six.moves.urllib.error import HTTPError from functools import wraps from gzip import GzipFile from io import BytesIO +import mimetypes import zlib import pickle @@ -2024,6 +2025,24 @@ def test_boto3_get_object(): e.exception.response["Error"]["Code"].should.equal("NoSuchKey") +@mock_s3 +def test_boto3_s3_content_type(): + s3 = boto3.resource("s3", region_name=DEFAULT_REGION_NAME) + my_bucket = s3.Bucket("my-cool-bucket") + my_bucket.create() + local_path = "test_s3.py" + s3_path = local_path + s3 = boto3.resource("s3", verify=False) + + with open(local_path, "rb") as _file: + content_type = mimetypes.guess_type(local_path) + s3.Object(my_bucket.name, s3_path).put( + ContentType=content_type[0], Body=_file, ACL="public-read" + ) + + s3.Object(my_bucket.name, s3_path).content_type.should.equal(content_type[0]) + + @mock_s3 def test_boto3_get_missing_object_with_part_number(): s3 = boto3.resource("s3", region_name=DEFAULT_REGION_NAME) From e9930b0cb2dd66e0057511f742ae5021ad377407 Mon Sep 17 00:00:00 2001 From: Bert Blommers Date: Tue, 10 Mar 2020 13:30:38 +0000 Subject: [PATCH 2/2] S3 - test fix - Use plain text as content, instead of file --- tests/test_s3/test_s3.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/test_s3/test_s3.py b/tests/test_s3/test_s3.py index 48939be26..800daaef8 100644 --- a/tests/test_s3/test_s3.py +++ b/tests/test_s3/test_s3.py @@ -2030,17 +2030,15 @@ def test_boto3_s3_content_type(): s3 = boto3.resource("s3", region_name=DEFAULT_REGION_NAME) my_bucket = s3.Bucket("my-cool-bucket") my_bucket.create() - local_path = "test_s3.py" - s3_path = local_path + s3_path = "test_s3.py" s3 = boto3.resource("s3", verify=False) - with open(local_path, "rb") as _file: - content_type = mimetypes.guess_type(local_path) - s3.Object(my_bucket.name, s3_path).put( - ContentType=content_type[0], Body=_file, ACL="public-read" - ) + content_type = "text/python-x" + s3.Object(my_bucket.name, s3_path).put( + ContentType=content_type, Body=b"some python code", ACL="public-read" + ) - s3.Object(my_bucket.name, s3_path).content_type.should.equal(content_type[0]) + s3.Object(my_bucket.name, s3_path).content_type.should.equal(content_type) @mock_s3