-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_rev.py
More file actions
42 lines (35 loc) · 1.69 KB
/
test_rev.py
File metadata and controls
42 lines (35 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from rev import APIClient, UserServices, DatabaseClient
import pytest
#preparing the mocks
def test_register_user(mocker):
"""testing UserServices with mocked APIClient and DatabaseClient"""
mock_api_client= mocker.Mock(spec= APIClient)
mock_db_client= mocker.Mock(spec= DatabaseClient)
"""setting return values for the mocked methods"""
mock_api_client.get_user_data.return_value= {
'username': 'ibrahim sulaimon',
'email': 'ibrahimsulaimon@gmail.com',
'age': 0
}
mock_db_client.save_user.return_value= {
'username': 'ibrahim sulaimon',
'email': 'ibrahimsulaimon@gmail.com',
'age': 0
}
"""creating UserServices instance with the mocked clients"""
services= UserServices(mock_api_client, mock_db_client)
"""calling the register_user method"""
result= services.register_user('ibrahim sulaimon', 'ibrahimsulaimon@gmail.com', 0)
#assertations
"""checking the result and that the mocked methods were called correctly"""
assert result == ('IBRAHIM SULAIMON')
mock_api_client.get_user_data.assert_called_once_with('ibrahim sulaimon','ibrahimsulaimon@gmail.com', 0)
mock_db_client.save_user.assert_called_once_with('ibrahim sulaimon','ibrahimsulaimon@gmail.com', 0)
# #live integration test (with real APIClient and DatabaseClient)
# def test_register_user_integration():
# """Integration test for UserServices with real APIClient and DatabaseClient"""
# api_client= APIClient()
# db_client= DatabaseClient('test_users.db')
# servers= UserServices(api_client, db_client)
# result= servers.register_user('sulaimon majeed', 'sulaimonmajeed@example.com', 25)
# assert result == 'SULAIMON MAJEED'