Skip to content

Commit 525cd6e

Browse files
リファクタリングついでにテストFIX
1 parent df662da commit 525cd6e

File tree

3 files changed

+94
-34
lines changed

3 files changed

+94
-34
lines changed

src/common/settings.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,25 @@
8585
'minLength': 12,
8686
'maxLength': 12
8787
}
88+
},
89+
'fraud_user': {
90+
'reason': {
91+
'type': 'string',
92+
},
93+
'plagiarism_url': {
94+
'type': 'string',
95+
'format': 'uri',
96+
'maxLength': 2048
97+
},
98+
'plagiarism_description': {
99+
'type': 'string',
100+
'maxLength': 65535
101+
},
102+
'illegal_content': {
103+
'type': 'string',
104+
'maxLength': 65535
105+
},
106+
88107
}
89108
}
90109

src/handlers/me/articles/fraud/create/me_articles_fraud_create.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@ def get_schema(self):
1515
'type': 'object',
1616
'properties': {
1717
'article_id': settings.parameters['article_id'],
18-
'reason': {
19-
'type': 'string',
20-
'enum': settings.FRAUD_REASONS
21-
},
22-
'plagiarism_url': {
23-
'type': 'string',
24-
},
25-
'plagiarism_description': {
26-
'type': 'string'
27-
},
28-
'illegal_content': {
29-
'type': 'string'
30-
},
18+
'reason': settings.parameters['fraud_user']['reason'],
19+
'plagiarism_url': settings.parameters['fraud_user']['plagiarism_url'],
20+
'plagiarism_description': settings.parameters['fraud_user']['plagiarism_description'],
21+
'illegal_content': settings.parameters['fraud_user']['illegal_content']
3122
},
23+
'anyOf': [
24+
{
25+
'properties': {
26+
'reason': {
27+
'enum': settings.FRAUD_REASONS
28+
},
29+
}
30+
31+
}
32+
],
3233
'required': ['article_id']
3334
}
3435

tests/handlers/me/articles/fraud/create/test_me_articles_fraud_create.py

Lines changed: 61 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def test_main_ok_exist_article_id(self):
8484
'pathParameters': {
8585
'article_id': self.article_fraud_user_table_items[0]['article_id']
8686
},
87+
'body': json.dumps({
88+
'reason': 'plagiarism',
89+
'plagiarism_url': 'http://test.com',
90+
'plagiarism_description': 'plagiarism description',
91+
'illegal_content': 'illegal content'
92+
}),
8793
'requestContext': {
8894
'authorizer': {
8995
'claims': {
@@ -103,12 +109,21 @@ def test_main_ok_exist_article_id(self):
103109

104110
target_article_id = params['pathParameters']['article_id']
105111
target_user_id = params['requestContext']['authorizer']['claims']['cognito:username']
112+
body = json.loads(params['body'])
113+
target_reason = body['reason']
114+
target_plagiarism_url = body['plagiarism_url']
115+
target_plagiarism_description = body['plagiarism_description']
116+
target_illegal_content = body['illegal_content']
106117

107118
article_fraud_user = self.get_article_fraud_user(target_article_id, target_user_id)
108119

109120
expected_items = {
110121
'article_id': target_article_id,
111122
'user_id': target_user_id,
123+
'reason': target_reason,
124+
'plagiarism_url': target_plagiarism_url,
125+
'plagiarism_description': target_plagiarism_description,
126+
'illegal_content': target_illegal_content,
112127
'created_at': 1520150272000003
113128
}
114129

@@ -185,38 +200,63 @@ def test_validation_article_id_min(self):
185200

186201
def test_validation_invalid_reason(self):
187202
params = {
188-
'pathParameters': {
189-
'article_id': self.article_fraud_user_table_items[1]['article_id']
190-
},
191-
'body': json.dumps({'reason': 'abcde'}),
192-
'requestContext': {
193-
'authorizer': {
194-
'claims': {
195-
'cognito:username': 'test03'
196-
}
197-
}
198-
}
203+
'body': json.dumps({'reason': 'abcde'})
199204
}
200205
self.assert_bad_request(params)
201206

202207
def test_validation_required_plagiarism_url_when_reason_is_plagiarism(self):
203208
params = {
204-
'pathParameters': {
205-
'article_id': self.article_fraud_user_table_items[2]['article_id']
206-
},
207209
'body': json.dumps(
208210
{
209211
'reason': 'plagiarism',
210212
'plagiarism_url': '',
211213
}
212-
),
213-
'requestContext': {
214-
'authorizer': {
215-
'claims': {
216-
'cognito:username': 'test03'
217-
}
214+
)
215+
}
216+
self.assert_bad_request(params)
217+
218+
def test_validation_required_plagiarism_description_when_reason_is_plagiarism(self):
219+
params = {
220+
'body': json.dumps(
221+
{
222+
'reason': 'plagiarism',
223+
'plagiarism_url': 'http://test.com',
224+
'plagiarism_description': '',
218225
}
219-
}
226+
)
227+
}
228+
self.assert_bad_request(params)
229+
230+
def test_validation_invalid_plagiarism_url_when_reason_is_plagiarism(self):
231+
params = {
232+
'body': json.dumps(
233+
{
234+
'reason': 'plagiarism',
235+
'plagiarism_url': 'aaa'
236+
}
237+
)
238+
}
239+
self.assert_bad_request(params)
240+
241+
def test_validation_required_illegal_content_when_reason_is_illegal(self):
242+
params = {
243+
'body': json.dumps(
244+
{
245+
'reason': 'illegal',
246+
'illegal_content': '',
247+
}
248+
)
249+
}
250+
self.assert_bad_request(params)
251+
252+
def test_validation_required_illegal_content_when_reason_is_other(self):
253+
params = {
254+
'body': json.dumps(
255+
{
256+
'reason': 'other',
257+
'illegal_content': '',
258+
}
259+
)
220260
}
221261
self.assert_bad_request(params)
222262

0 commit comments

Comments
 (0)