@@ -105,10 +105,10 @@ def test_main_ok_exist_article_id(self):
105105 target_article_id = params ['pathParameters' ]['article_id' ]
106106 target_user_id = params ['requestContext' ]['authorizer' ]['claims' ]['cognito:username' ]
107107 body = json .loads (params ['body' ])
108- target_reason = body [ 'reason' ]
109- target_plagiarism_url = body [ 'plagiarism_url' ]
110- target_plagiarism_description = body [ 'plagiarism_description' ]
111- target_illegal_content = body [ 'illegal_content' ]
108+ target_reason = body . get ( 'reason' )
109+ target_plagiarism_url = body . get ( 'plagiarism_url' )
110+ target_plagiarism_description = body . get ( 'plagiarism_description' )
111+ target_illegal_content = body . get ( 'illegal_content' )
112112
113113 article_fraud_user = self .get_article_fraud_user (target_article_id , target_user_id )
114114
@@ -202,65 +202,83 @@ def test_validation_article_id_min(self):
202202 self .assert_bad_request (params )
203203
204204 def test_validation_invalid_reason (self ):
205- params = {
205+ body = {
206206 'body' : json .dumps ({'reason' : 'abcde' })
207207 }
208+ params = dict (self .get_parameters_other_than_body (), ** body )
208209 self .assert_bad_request (params )
209210
210- def test_validation_required_plagiarism_url_when_reason_is_plagiarism (self ):
211- params = {
211+ def test_validation_required_plagiarism_detail_when_reason_is_plagiarism (self ):
212+ body = {
212213 'body' : json .dumps (
213214 {
214215 'reason' : 'plagiarism' ,
215216 'plagiarism_url' : '' ,
217+ 'plagiarism_description' : ''
216218 }
217219 )
218220 }
221+ params = dict (self .get_parameters_other_than_body (), ** body )
219222 self .assert_bad_request (params )
220223
221- def test_validation_required_plagiarism_description_when_reason_is_plagiarism (self ):
222- params = {
224+ def test_validation_invalid_plagiarism_url_when_reason_is_plagiarism (self ):
225+ body = {
223226 'body' : json .dumps (
224227 {
225228 'reason' : 'plagiarism' ,
226- 'plagiarism_url' : 'http://test.com' ,
227- 'plagiarism_description' : '' ,
229+ 'plagiarism_url' : 'aaa'
228230 }
229231 )
230232 }
233+ params = dict (self .get_parameters_other_than_body (), ** body )
231234 self .assert_bad_request (params )
232235
233- def test_validation_invalid_plagiarism_url_when_reason_is_plagiarism (self ):
234- params = {
236+ def test_validation_required_illegal_content_when_reason_is_illegal (self ):
237+ body = {
235238 'body' : json .dumps (
236239 {
237- 'reason' : 'plagiarism ' ,
238- 'plagiarism_url ' : 'aaa '
240+ 'reason' : 'illegal ' ,
241+ 'illegal_content ' : ''
239242 }
240243 )
241244 }
245+ params = dict (self .get_parameters_other_than_body (), ** body )
242246 self .assert_bad_request (params )
243247
244- def test_validation_required_illegal_content_when_reason_is_illegal (self ):
245- params = {
248+ def test_validation_required_illegal_content_when_reason_is_other (self ):
249+ body = {
246250 'body' : json .dumps (
247251 {
248- 'reason' : 'illegal ' ,
249- 'illegal_content' : '' ,
252+ 'reason' : 'other ' ,
253+ 'illegal_content' : ''
250254 }
251255 )
252256 }
257+ params = dict (self .get_parameters_other_than_body (), ** body )
253258 self .assert_bad_request (params )
254259
255- def test_validation_required_illegal_content_when_reason_is_other (self ):
256- params = {
260+ def test_validation_plagiarism_description_max (self ):
261+ body = {
257262 'body' : json .dumps (
258263 {
259- 'reason' : 'other ' ,
260- 'illegal_content ' : '' ,
264+ 'reason' : 'plagiarism ' ,
265+ 'plagiarism_description ' : u'あ' * 1001
261266 }
262267 )
263268 }
269+ params = dict (self .get_parameters_other_than_body (), ** body )
270+ self .assert_bad_request (params )
271+
272+ def test_validation_illegal_content_max (self ):
273+ body = {
274+ 'body' : json .dumps (
275+ {
276+ 'reason' : 'illegal' ,
277+ 'illegal_content' : u'あ' * 1001
278+ }
279+ )
280+ }
281+ params = dict (self .get_parameters_other_than_body (), ** body )
264282 self .assert_bad_request (params )
265283
266284 def get_article_fraud_user (self , article_id , user_id ):
@@ -269,3 +287,18 @@ def get_article_fraud_user(self, article_id, user_id):
269287 }
270288 article_fraud_user_table = self .dynamodb .Table (os .environ ['ARTICLE_FRAUD_USER_TABLE_NAME' ])
271289 return article_fraud_user_table .query (** query_params )['Items' ][0 ]
290+
291+ def get_parameters_other_than_body (self ):
292+ basic_params = {
293+ 'pathParameters' : {
294+ 'article_id' : self .article_fraud_user_table_items [1 ]['article_id' ]
295+ },
296+ 'requestContext' : {
297+ 'authorizer' : {
298+ 'claims' : {
299+ 'cognito:username' : 'test03'
300+ }
301+ }
302+ }
303+ }
304+ return basic_params
0 commit comments