File tree 2 files changed +7
-2
lines changed
python_test_example/flask_app 2 files changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ def index():
18
18
def predict ():
19
19
print ('Call predict in app' )
20
20
target = 'A'
21
- if not service .check_model :
21
+ if not service .check_model () :
22
22
return make_response (jsonify ({'message' : 'Service Unavailable' }), 503 )
23
23
result = {'result' : service .predict (target )}
24
24
return make_response (jsonify (result ), 200 )
Original file line number Diff line number Diff line change 1
1
import json
2
2
from unittest import TestCase , main
3
- from unittest .mock import Mock , patch
3
+ from unittest .mock import patch
4
4
5
5
print ('In app_test' )
6
6
@@ -38,5 +38,10 @@ def test_predict_data(self):
38
38
response = self .client .post ('/predict' )
39
39
self .assertIsInstance (json .loads (response .data )['result' ], float )
40
40
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
+
41
46
if __name__ == '__main__' :
42
47
main ()
You can’t perform that action at this time.
0 commit comments