File tree Expand file tree Collapse file tree 4 files changed +62
-30
lines changed
Expand file tree Collapse file tree 4 files changed +62
-30
lines changed Original file line number Diff line number Diff line change @@ -25,17 +25,31 @@ def get_schema(self):
2525 def get_headers_schema (self ):
2626 return {
2727 'type' : 'object' ,
28- 'properties' : {
29- 'content-type' : {
30- 'type' : 'string' ,
31- 'enum' : [
32- 'image/gif' ,
33- 'image/jpeg' ,
34- 'image/png'
35- ]
36- }
37- },
38- 'required' : ['content-type' ]
28+ "oneOf" : [{
29+ 'properties' : {
30+ 'content-type' : {
31+ 'type' : 'string' ,
32+ 'enum' : [
33+ 'image/gif' ,
34+ 'image/jpeg' ,
35+ 'image/png'
36+ ]
37+ }
38+ },
39+ 'required' : ['content-type' ]
40+ }, {
41+ 'properties' : {
42+ 'Content-Type' : {
43+ 'type' : 'string' ,
44+ 'enum' : [
45+ 'image/gif' ,
46+ 'image/jpeg' ,
47+ 'image/png'
48+ ]
49+ }
50+ },
51+ 'required' : ['Content-Type' ]
52+ }]
3953 }
4054
4155 def validate_image_data (self , image_data ):
@@ -60,7 +74,9 @@ def validate_params(self):
6074 )
6175
6276 def exec_main_proc (self ):
63- ext = self .headers ['content-type' ].split ('/' )[1 ]
77+ content_type = self .headers .get ('content-type' ) \
78+ if self .headers .get ('content-type' ) is not None else self .headers .get ('Content-Type' )
79+ ext = content_type .split ('/' )[1 ]
6480 user_id = self .event ['requestContext' ]['authorizer' ]['claims' ]['cognito:username' ]
6581 key = settings .S3_ARTICLES_IMAGES_PATH + \
6682 user_id + '/' + self .params ['article_id' ] + '/' + str (uuid .uuid4 ()) + '.' + ext
@@ -69,7 +85,7 @@ def exec_main_proc(self):
6985 self .s3 .Bucket (os .environ ['DIST_S3_BUCKET_NAME' ]).put_object (
7086 Body = image_data ,
7187 Key = key ,
72- ContentType = self . headers [ 'content-type' ]
88+ ContentType = content_type
7389 )
7490
7591 return {
Original file line number Diff line number Diff line change @@ -23,17 +23,31 @@ def get_schema(self):
2323 def get_headers_schema (self ):
2424 return {
2525 'type' : 'object' ,
26- 'properties' : {
27- 'content-type' : {
28- 'type' : 'string' ,
29- 'enum' : [
30- 'image/gif' ,
31- 'image/jpeg' ,
32- 'image/png'
33- ]
34- }
35- },
36- 'required' : ['content-type' ]
26+ "oneOf" : [{
27+ 'properties' : {
28+ 'content-type' : {
29+ 'type' : 'string' ,
30+ 'enum' : [
31+ 'image/gif' ,
32+ 'image/jpeg' ,
33+ 'image/png'
34+ ]
35+ }
36+ },
37+ 'required' : ['content-type' ]
38+ }, {
39+ 'properties' : {
40+ 'Content-Type' : {
41+ 'type' : 'string' ,
42+ 'enum' : [
43+ 'image/gif' ,
44+ 'image/jpeg' ,
45+ 'image/png'
46+ ]
47+ }
48+ },
49+ 'required' : ['Content-Type' ]
50+ }]
3751 }
3852
3953 def validate_image_data (self , image_data ):
@@ -51,7 +65,9 @@ def validate_params(self):
5165 validate (self .event .get ('headers' ), self .get_headers_schema ())
5266
5367 def exec_main_proc (self ):
54- ext = self .headers ['content-type' ].split ('/' )[1 ]
68+ content_type = self .headers .get ('content-type' ) \
69+ if self .headers .get ('content-type' ) is not None else self .headers .get ('Content-Type' )
70+ ext = content_type .split ('/' )[1 ]
5571 user_id = self .event ['requestContext' ]['authorizer' ]['claims' ]['cognito:username' ]
5672 key = settings .S3_INFO_ICON_PATH + \
5773 user_id + '/icon/' + str (uuid .uuid4 ()) + '.' + ext
@@ -60,7 +76,7 @@ def exec_main_proc(self):
6076 self .s3 .Bucket (os .environ ['DIST_S3_BUCKET_NAME' ]).put_object (
6177 Body = image_data ,
6278 Key = key ,
63- ContentType = self . headers [ 'content-type' ]
79+ ContentType = content_type
6480 )
6581
6682 icon_image_url = 'https://' + os .environ ['DOMAIN' ] + '/' + key
Original file line number Diff line number Diff line change @@ -103,7 +103,7 @@ def test_main_ok_status_public(self):
103103 self .assertTrue (self .equal_size_to_s3_image (key , image_data .size ))
104104
105105 @patch ('uuid.uuid4' , MagicMock (return_value = 'uuid' ))
106- def test_main_ok_status_draft (self ):
106+ def test_main_ok_status_draft_and_content_type_is_upper_case (self ):
107107 image_data = Image .new ('RGB' , (1 , 1 ))
108108 buf = BytesIO ()
109109 image_format = 'png'
@@ -112,7 +112,7 @@ def test_main_ok_status_draft(self):
112112 target_article_info = self .article_info_table_items [1 ]
113113 params = {
114114 'headers' : {
115- 'content-type ' : 'image/' + image_format
115+ 'Content-Type ' : 'image/' + image_format
116116 },
117117 'pathParameters' : {
118118 'article_id' : target_article_info ['article_id' ]
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ def test_main_ok(self):
107107 self .assertTrue (self .equal_size_to_s3_image (key , image_data .size ))
108108
109109 @patch ('uuid.uuid4' , MagicMock (return_value = 'uuid' ))
110- def test_main_ok_exists_icon_image_url_png (self ):
110+ def test_main_ok_exists_icon_image_url_png_and_content_type_is_upper_case (self ):
111111 image_data = Image .new ('RGB' , (150 , 120 ))
112112 buf = BytesIO ()
113113 image_format = 'png'
@@ -116,7 +116,7 @@ def test_main_ok_exists_icon_image_url_png(self):
116116 target_user = self .users_table_items [1 ]
117117 params = {
118118 'headers' : {
119- 'content-type ' : 'image/' + image_format
119+ 'Content-Type ' : 'image/' + image_format
120120 },
121121 'body' : json .dumps ({'icon_image' : base64 .b64encode (buf .getvalue ()).decode ('ascii' )}),
122122 'requestContext' : {
You can’t perform that action at this time.
0 commit comments