forked from rbignon/doctoshotgun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_cli_args.py
115 lines (90 loc) · 3.15 KB
/
test_cli_args.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import responses
from unittest.mock import patch, MagicMock
from doctoshotgun import Application, DoctolibDE, DoctolibFR, MasterPatientPage
CENTERS = [
{
"name_with_title": "Doktor",
"city": "koln",
},
{
"name_with_title": "Doktor2",
"city": "koln",
},
{
"name_with_title": "Doktor",
"city": "neuss",
},
]
@responses.activate
@patch('doctoshotgun.DoctolibDE')
def test_center_arg_should_filter_centers(MockDoctolibDE, tmp_path):
"""
Check that booking is performed in correct city
"""
# prepare
mock_doctolib_de = get_mocked_doctolib(MockDoctolibDE)
# call
center = 'Doktor'
city = 'koln'
call_application(city, cli_args=['--center', center])
# assert
assert mock_doctolib_de.get_patients.called
assert mock_doctolib_de.try_to_book.called
for call_args_list in mock_doctolib_de.try_to_book.call_args_list:
assert call_args_list.args[0]['name_with_title'] == center
assert call_args_list.args[0]['city'] == city
@responses.activate
@patch('doctoshotgun.DoctolibDE')
def test_center_exclude_arg_should_filter_excluded_centers(MockDoctolibDE, tmp_path):
"""
Check that booking is performed in correct city
"""
# prepare
mock_doctolib_de = get_mocked_doctolib(MockDoctolibDE)
# call
excluded_center = 'Doktor'
city = 'koln'
call_application(city, cli_args=['--center-exclude', excluded_center])
# assert
assert mock_doctolib_de.get_patients.called
assert mock_doctolib_de.try_to_book.called
for call_args_list in mock_doctolib_de.try_to_book.call_args_list:
assert call_args_list.args[0]['name_with_title'] != excluded_center
assert call_args_list.args[0]['city'] == city
@responses.activate
@patch('doctoshotgun.DoctolibDE')
def test_config_file_should_be_used(MockDoctolibDE, tmp_path):
"""
Check that config file is used corrrectly
"""
# prepare
mock_doctolib_de = get_mocked_doctolib(MockDoctolibDE)
# call
call_application_without_default_args(
cli_args=['@test_fixtures/docto.config'])
# assert
assert mock_doctolib_de.try_to_book.called
def get_mocked_doctolib(MockDoctolibDE):
mock_doctolib_de = MagicMock(wraps=DoctolibDE)
MockDoctolibDE.return_value = mock_doctolib_de
mock_doctolib_de.vaccine_motives = DoctolibDE.vaccine_motives
mock_doctolib_de.KEY_PFIZER = DoctolibDE.KEY_PFIZER
mock_doctolib_de.KEY_MODERNA = DoctolibDE.KEY_MODERNA
mock_doctolib_de.KEY_JANSSEN = DoctolibDE.KEY_JANSSEN
mock_doctolib_de.get_patients.return_value = [
{"first_name": 'First', "last_name": 'Name'}
]
mock_doctolib_de.do_login.return_value = True
mock_doctolib_de.find_centers.return_value = CENTERS
mock_doctolib_de.try_to_book.return_value = True
return mock_doctolib_de
def call_application(city, cli_args=[]):
assert 0 == Application.main(
Application(),
cli_args=["de", city, "[email protected]", "1234"] + cli_args
)
def call_application_without_default_args(cli_args):
assert 0 == Application.main(
Application(),
cli_args=cli_args
)