Skip to content

Commit e097db8

Browse files
committed
VED-470: Add tests for content type parsing.
1 parent 72dd6a2 commit e097db8

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

mesh_processor/tests/test_converter.py

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def test_non_multipart_content_type(self):
5959
head_archive_response = s3.head_object(Bucket="source-bucket", Key="archive/test-csv-file.csv")
6060
assert head_archive_response["ResponseMetadata"]["HTTPStatusCode"] == 200
6161

62-
def test_non_multipart_content_type_no_mesh_metadata(self):
62+
def test_non_multipart_content_type_without_mesh_metadata(self):
6363
s3 = boto3.client("s3", region_name="eu-west-2")
6464
s3.put_object(
6565
Bucket="source-bucket",
@@ -149,8 +149,10 @@ def test_multipart_content_type(self):
149149
response = s3.get_object(Bucket="destination-bucket", Key="test-csv-file.csv")
150150
body = response["Body"].read().decode("utf-8")
151151
assert body == "some CSV content"
152+
content_type = response["ContentType"]
153+
assert content_type == "text/csv"
152154

153-
def test_multipart_content_type_without_filename_from_headers(self):
155+
def test_multipart_content_type_without_filename_in_headers(self):
154156
cases = [
155157
(
156158
"no filename in header",
@@ -194,6 +196,33 @@ def test_multipart_content_type_without_filename_from_headers(self):
194196
body = response["Body"].read().decode("utf-8")
195197
assert body == "some CSV content"
196198

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+
197226
def test_multipart_content_type_with_unix_line_endings(self):
198227
body = "\r\n".join([
199228
"",

0 commit comments

Comments
 (0)