File tree 2 files changed +20
-6
lines changed
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,10 @@ def post(route, body):
14
14
)
15
15
json = resp .json ()
16
16
17
- # deal with error handling later
17
+ print (json )
18
+
19
+ # handle errors
20
+ if json .get ('status' ) != '200' :
21
+ return {'error' : json .get ('reason' )}
18
22
19
23
return json
Original file line number Diff line number Diff line change 2
2
import requests
3
3
from gm_api import GM_Api as GM_Api
4
4
5
- def test_post (mocker ):
5
+ def test_post_success (mocker ):
6
6
mock = mocker .patch ('requests.post' )
7
- def json ():
8
- return ' this is a mock'
9
- mock .return_value .json = json
7
+ def success_json ():
8
+ return { 'status' : '200' , 'data' : ' this is a mock'}
9
+ mock .return_value .json = success_json
10
10
11
11
resp = GM_Api .post ('/getVehicleInfoService' , {'id' : '1234' })
12
12
mock .assert_called_with ('http://gmapi.azurewebsites.net/getVehicleInfoService' , json = {'id' : '1234' , 'responseType' : 'JSON' })
13
- assert (resp == 'this is a mock' )
13
+ assert (resp == {'status' : '200' , 'data' : 'this is a mock' })
14
+
15
+ def test_post_fail (mocker ):
16
+ mock = mocker .patch ('requests.post' )
17
+ def fail_json ():
18
+ return {'status' : '404' , 'reason' : 'Vehicle id: 1000 not found.' }
19
+ mock .return_value .json = fail_json
20
+
21
+ resp = GM_Api .post ('/getVehicleInfoService' , {'id' : '1000' })
22
+ mock .assert_called_with ('http://gmapi.azurewebsites.net/getVehicleInfoService' , json = {'id' : '1000' , 'responseType' : 'JSON' })
23
+ assert (resp == {'error' : 'Vehicle id: 1000 not found.' })
You can’t perform that action at this time.
0 commit comments