@@ -48,11 +48,18 @@ def test_non_multipart_content_type(self):
4848 result = invoke_lambda ("test-csv-file.csv" )
4949 self .assertEqual (result ["statusCode" ], 200 )
5050
51- response = s3 .get_object (Bucket = "destination-bucket" , Key = "overridden-filename.csv" )
52- body = response ["Body" ].read ().decode ("utf-8" )
51+ get_target_response = s3 .get_object (Bucket = "destination-bucket" , Key = "overridden-filename.csv" )
52+ body = get_target_response ["Body" ].read ().decode ("utf-8" )
5353 assert body == "some CSV content"
5454
55- def test_non_multipart_content_type_no_mesh_metadata (self ):
55+ with self .assertRaises (ClientError ) as e :
56+ s3 .head_object (Bucket = "source-bucket" , Key = "test-csv-file.csv" )
57+ self .assertEqual (e .exception .response ["Error" ]["Code" ], "404" )
58+
59+ head_archive_response = s3 .head_object (Bucket = "source-bucket" , Key = "archive/test-csv-file.csv" )
60+ assert head_archive_response ["ResponseMetadata" ]["HTTPStatusCode" ] == 200
61+
62+ def test_non_multipart_content_type_without_mesh_metadata (self ):
5663 s3 = boto3 .client ("s3" , region_name = "eu-west-2" )
5764 s3 .put_object (
5865 Bucket = "source-bucket" ,
@@ -142,8 +149,10 @@ def test_multipart_content_type(self):
142149 response = s3 .get_object (Bucket = "destination-bucket" , Key = "test-csv-file.csv" )
143150 body = response ["Body" ].read ().decode ("utf-8" )
144151 assert body == "some CSV content"
152+ content_type = response ["ContentType" ]
153+ assert content_type == "text/csv"
145154
146- def test_multipart_content_type_without_filename_from_headers (self ):
155+ def test_multipart_content_type_without_filename_in_headers (self ):
147156 cases = [
148157 (
149158 "no filename in header" ,
@@ -187,6 +196,33 @@ def test_multipart_content_type_without_filename_from_headers(self):
187196 body = response ["Body" ].read ().decode ("utf-8" )
188197 assert body == "some CSV content"
189198
199+ def test_multipart_content_type_without_content_type_in_headers (self ):
200+ body = "\r \n " .join ([
201+ "" ,
202+ "--12345678" ,
203+ 'Content-Disposition: form-data; name="File"; filename="test-csv-file.csv"' ,
204+ "" ,
205+ "some CSV content" ,
206+ "--12345678--" ,
207+ ""
208+ ])
209+ s3 = boto3 .client ("s3" , region_name = "eu-west-2" )
210+ s3 .put_object (
211+ Bucket = "source-bucket" ,
212+ Key = "test-dat-file.dat" ,
213+ Body = body .encode ("utf-8" ),
214+ ContentType = "multipart/form-data; boundary=12345678" ,
215+ )
216+
217+ result = invoke_lambda ("test-dat-file.dat" )
218+ self .assertEqual (result ["statusCode" ], 200 )
219+
220+ response = s3 .get_object (Bucket = "destination-bucket" , Key = "test-csv-file.csv" )
221+ body = response ["Body" ].read ().decode ("utf-8" )
222+ assert body == "some CSV content"
223+ content_type = response ["ContentType" ]
224+ assert content_type == "application/octet-stream"
225+
190226 def test_multipart_content_type_with_unix_line_endings (self ):
191227 body = "\r \n " .join ([
192228 "" ,
0 commit comments