2
2
from users import get_users , get_user
3
3
from unittest .mock import patch , Mock
4
4
5
+
5
6
class BasicTests (unittest .TestCase ):
6
7
def test_request_response (self ):
7
8
mock_get_patcher = patch ('users.requests.get' )
@@ -16,7 +17,7 @@ def test_request_response(self):
16
17
mock_get = mock_get_patcher .start ()
17
18
18
19
# Configure the mock to return a response with status code 200.
19
- mock_get .return_value = Mock (status_code = 200 )
20
+ mock_get .return_value = Mock (status_code = 200 )
20
21
mock_get .return_value .json .return_value = users
21
22
22
23
# Call the service, which will send a request to the server.
@@ -33,14 +34,18 @@ def test_request_response(self):
33
34
def test_get_one_user (self , mock_get_users ):
34
35
"""Test for getting one user using their userID"""
35
36
users = [
36
- {'phone' : '514-794-6957' , 'first_name' : 'Brant' , 'last_name' : 'Mekhi' , 'id' : 0 },
37
- {'phone' : '772-370-0117' , 'first_name' : 'Thalia' , 'last_name' : 'Kenyatta' , 'id' : 1 },
38
- {'phone' : '176-290-7637' , 'first_name' : 'Destin' , 'last_name' : 'Soledad' , 'id' : 2 }
39
- ]
37
+ {'phone' : '514-794-6957' , 'first_name' : 'Brant' ,
38
+ 'last_name' : 'Mekhi' , 'id' : 0 },
39
+ {'phone' : '772-370-0117' , 'first_name' : 'Thalia' ,
40
+ 'last_name' : 'Kenyatta' , 'id' : 1 },
41
+ {'phone' : '176-290-7637' , 'first_name' : 'Destin' ,
42
+ 'last_name' : 'Soledad' , 'id' : 2 }
43
+ ]
40
44
mock_get_users .return_value = Mock ()
41
45
mock_get_users .return_value .json .return_value = users
42
46
user = get_user (2 )
43
47
self .assertEqual (user , users [2 ])
44
48
49
+
45
50
if __name__ == "__main__" :
46
51
unittest .main ()
0 commit comments