8000 Add test_predict_503 to AppTestCase · suaaa7/samplecode-for-qiita@cc439d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit cc439d7

Browse files
committed
Add test_predict_503 to AppTestCase
1 parent 96026eb commit cc439d7

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

python_test_example/flask_app/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def index():
1818
def predict():
1919
print('Call predict in app')
2020
target = 'A'
21-
if not service.check_model:
21+
if not service.check_model():
2222
return make_response(jsonify({'message': 'Service Unavailable'}), 503)
2323
result = {'result': service.predict(target)}
2424
return make_response(jsonify(result), 200)

python_test_example/flask_app/app_test.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import json
22
from unittest import TestCase, main
3-
from unittest.mock import Mock, patch
3+
from unittest.mock import patch
44

55
print('In app_test')
66

@@ -38,5 +38,10 @@ def test_predict_data(self):
3838
response = self.client.post('/predict')
3939
self.assertIsInstance(json.loads(response.data)['result'], float)
4040

41+
@patch('flask_app.service.Service.check_model', return_value=False)
42+
def test_predict_503(self, mock):
43+
response = self.client.post('/predict')
44+
self.assertEqual(response.status_code, 503)
45+
4146
if __name__ == '__main__':
4247
main()

0 commit comments

Comments
 (0)
0