forked from rbignon/doctoshotgun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_browser.py
588 lines (492 loc) · 25.7 KB
/
test_browser.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
import pytest
from requests.adapters import Response
import responses
from html import escape
import lxml.html as html
import json
import datetime
from woob.browser.browsers import Browser
from woob.browser.exceptions import ServerError
from doctoshotgun import CentersPage, DoctolibDE, DoctolibFR, CenterBookingPage
# globals
FIXTURES_FOLDER = "test_fixtures"
@responses.activate
def test_find_centers_fr_returns_503_should_continue(tmp_path):
"""
Check that find_centers doesn't raise a ServerError in case of 503 HTTP response
"""
docto = DoctolibFR("[email protected]",
"1234", responses_dirname=tmp_path)
docto.BASEURL = "https://127.0.0.1"
responses.add(
responses.GET,
"https://127.0.0.1/vaccination-covid-19/Paris?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=6971&ref_visit_motive_ids%5B%5D=8192&ref_visit_motive_ids%5B%5D=7005&ref_visit_motive_ids%5B%5D=7004&ref_visit_motive_ids%5B%5D=8193&ref_visit_motive_ids%5B%5D=7945&ref_visit_motive_ids%5B%5D=7107&ref_visit_motive_ids%5B%5D=7108&page=1",
status=503
)
# this should not raise an exception
for _ in docto.find_centers(["Paris"]):
pass
@responses.activate
def test_find_centers_de_returns_503_should_continue(tmp_path):
"""
Check that find_centers doesn't raise a ServerError in case of 503 HTTP response
"""
docto = DoctolibDE("[email protected]",
"1234", responses_dirname=tmp_path)
docto.BASEURL = "https://127.0.0.1"
responses.add(
responses.GET,
"https://127.0.0.1/impfung-covid-19-corona/M%C3%BCnchen?ref_visit_motive_ids%5B%5D=6768&ref_visit_motive_ids%5B%5D=6769&ref_visit_motive_ids%5B%5D=6936&ref_visit_motive_ids%5B%5D=6937&ref_visit_motive_ids%5B%5D=7978&ref_visit_motive_ids%5B%5D=7109&ref_visit_motive_ids%5B%5D=7110&page=1",
status=503
)
# this should not raise an exception
for _ in docto.find_centers(["München"]):
pass
@responses.activate
def test_find_centers_de_returns_520_should_continue(tmp_path):
"""
Check that find_centers doesn't raise a ServerError in case of 503 HTTP response
"""
docto = DoctolibDE("[email protected]",
"1234", responses_dirname=tmp_path)
docto.BASEURL = "https://127.0.0.1"
responses.add(
responses.GET,
"https://127.0.0.1/impfung-covid-19-corona/M%C3%BCnchen?ref_visit_motive_ids%5B%5D=6768&ref_visit_motive_ids%5B%5D=6769&ref_visit_motive_ids%5B%5D=6936&ref_visit_motive_ids%5B%5D=6937&ref_visit_motive_ids%5B%5D=7978&ref_visit_motive_ids%5B%5D=7109&ref_visit_motive_ids%5B%5D=7110&page=1",
status=520
)
# this should not raise an exception
for _ in docto.find_centers(["München"]):
pass
@responses.activate
def test_find_centers_fr_returns_502_should_fail(tmp_path):
"""
Check that find_centers raises an error in case of non-whitelisted status code
"""
docto = DoctolibFR("[email protected]",
"1234", responses_dirname=tmp_path)
docto.BASEURL = "https://127.0.0.1"
responses.add(
responses.GET,
"https://127.0.0.1/vaccination-covid-19/Paris?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=6971&ref_visit_motive_ids%5B%5D=8192&ref_visit_motive_ids%5B%5D=7005&ref_visit_motive_ids%5B%5D=7004&ref_visit_motive_ids%5B%5D=8193&ref_visit_motive_ids%5B%5D=7945&ref_visit_motive_ids%5B%5D=7107&ref_visit_motive_ids%5B%5D=7108&page=1",
status=502
)
# this should raise an exception
with pytest.raises(ServerError):
for _ in docto.find_centers(["Paris"]):
pass
@responses.activate
def test_find_centers_de_returns_502_should_fail(tmp_path):
"""
Check that find_centers raises an error in case of non-whitelisted status code
"""
docto = DoctolibDE("[email protected]",
"1234", responses_dirname=tmp_path)
docto.BASEURL = "https://127.0.0.1"
responses.add(
responses.GET,
"https://127.0.0.1/impfung-covid-19-corona/M%C3%BCnchen?ref_visit_motive_ids%5B%5D=6768&ref_visit_motive_ids%5B%5D=6769&ref_visit_motive_ids%5B%5D=6936&ref_visit_motive_ids%5B%5D=6937&ref_visit_motive_ids%5B%5D=7978&ref_visit_motive_ids%5B%5D=7109&ref_visit_motive_ids%5B%5D=7110&page=1",
status=502
)
# this should raise an exception
with pytest.raises(ServerError):
for _ in docto.find_centers(["München"]):
pass
@responses.activate
def test_get_next_page_fr_should_return_2_on_page_1(tmp_path):
"""
Check that get_next_page returns 2 when we are on page 1 and there is a next page available
"""
"""
Next (data-u decoded): /vaccination-covid-19-autres-professions-prioritaires/france?page=2&ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005
"""
htmlString = """
<div class="next-previous-links">
<div class="previous dl-rounded-borders dl-white-bg">
<span class="disabled">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.863 7.576l4.859-4.859a.6.6 0 01.848 0l.567.567a.6.6 0 01.001.847L7.288 8l3.85 3.869a.6.6 0 01-.001.847l-.567.567a.6.6 0 01-.848 0L4.863 8.424a.6.6 0 010-.848z"></path></svg>
Précédent
</span>
</div>
<div class="next dl-rounded-borders dl-white-bg">
<span data-u="=UDMwcTPEVTJCVTJzRWafVmdpR3bt9FdpNXa29lZlJnJwcTO20DR1UiQ
1Uyckl2XlZXa09WbfRXazlmdfZWZyZiM9U2ZhB3PlNmbhJnZvMXZylWY0lmc
vlmcw1ycu9WazNXZm9mcw1yclJHd1FWL5ETLklmdvNWLu9Wa0FmbpN2YhZ3L">
Suivant
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.137 8.424l-4.859 4.859a.6.6 0 01-.848 0l-.567-.567a.6.6 0 010-.847L8.712 8l-3.85-3.869a.6.6 0 010-.847l.567-.567a.6.6 0 01.848 0l4.859 4.859a.6.6 0 010 .848z"></path></svg>
</span>
</div>
</div>
"""
doc = html.document_fromstring(htmlString)
response = Response()
response._content = b'{}'
centers_page = CentersPage(browser=Browser(), response=response)
centers_page.doc = doc
next_page = centers_page.get_next_page()
assert next_page == 2
@responses.activate
def test_get_next_page_fr_should_return_3_on_page_2(tmp_path):
"""
Check that get_next_page returns 3 when we are on page 2 and next page is available
"""
"""
Previous (data-u decoded): /vaccination-covid-19-autres-professions-prioritaires/france?ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005
Next (data-u decoded): /vaccination-covid-19-autres-professions-prioritaires/france?page=3&ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005
"""
htmlString = """
<div class="next-previous-links">
<div class="previous dl-rounded-borders dl-white-bg">
<span data-u="==QNwAzN9QUNlIUNlMHZp9VZ2lGdv12X0l2cpZ3XmVmcmAzN
5YTPEVTJCVTJzRWafVmdpR3bt9FdpNXa29lZlJ3PlNmbhJnZvMXZylWY0lmc
vlmcw1ycu9WazNXZm9mcw1yclJHd1FWL5ETLklmdvNWLu9Wa0FmbpN2YhZ3L">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.863 7.576l4.859-4.859a.6.6 0 01.848 0l.567.567a.6.6 0 01.001.847L7.288 8l3.85 3.869a.6.6 0 01-.001.847l-.567.567a.6.6 0 01-.848 0L4.863 8.424a.6.6 0 010-.848z"></path></svg>
Précédent
</span>
</div>
<div class="next dl-rounded-borders dl-white-bg">
<span data-u="=UDMwcTPEVTJCVTJzRWafVmdpR3bt9FdpNXa29lZlJnJwcTO20DR1UiQ
1Uyckl2XlZXa09WbfRXazlmdfZWZyZyM9U2ZhB3PlNmbhJnZvMXZylWY0lmc
vlmcw1ycu9WazNXZm9mcw1yclJHd1FWL5ETLklmdvNWLu9Wa0FmbpN2YhZ3L">
Suivant
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.137 8.424l-4.859 4.859a.6.6 0 01-.848 0l-.567-.567a.6.6 0 010-.847L8.712 8l-3.85-3.869a.6.6 0 010-.847l.567-.567a.6.6 0 01.848 0l4.859 4.859a.6.6 0 010 .848z"></path></svg>
</span>
</div>
</div>
"""
doc = html.document_fromstring(htmlString)
response = Response()
response._content = b'{}'
centers_page = CentersPage(browser=Browser(), response=response)
centers_page.doc = doc
next_page = centers_page.get_next_page()
assert next_page == 3
@responses.activate
def test_get_next_page_fr_should_return_4_on_page_3(tmp_path):
"""
Check that get_next_page returns 4 when we are on page 3 and next page is available
"""
"""
Previous (data-u decoded): /vaccination-covid-19-autres-professions-prioritaires/france?page=2&ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005
Next (data-u decoded): /vaccination-covid-19-autres-professions-prioritaires/france?page=4&ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005
"""
htmlString = """
<div class="next-previous-links">
<div class="previous dl-rounded-borders dl-white-bg">
<span data-u="=UDMwcTPEVTJCVTJzRWafVmdpR3bt9FdpNXa29lZlJnJwcTO20DR1UiQ
1Uyckl2XlZXa09WbfRXazlmdfZWZyZiM9U2ZhB3PlNmbhJnZvMXZylWY0lmc
vlmcw1ycu9WazNXZm9mcw1yclJHd1FWL5ETLklmdvNWLu9Wa0FmbpN2YhZ3L">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.863 7.576l4.859-4.859a.6.6 0 01.848 0l.567.567a.6.6 0 01.001.847L7.288 8l3.85 3.869a.6.6 0 01-.001.847l-.567.567a.6.6 0 01-.848 0L4.863 8.424a.6.6 0 010-.848z"></path></svg>
Précédent
</span>
</div>
<div class="next dl-rounded-borders dl-white-bg">
<span data-u="=UDMwcTPEVTJCVTJzRWafVmdpR3bt9FdpNXa29lZlJnJwcTO20DR1UiQ
1Uyckl2XlZXa09WbfRXazlmdfZWZyZCN9U2ZhB3PlNmbhJnZvMXZylWY0lmc
vlmcw1ycu9WazNXZm9mcw1yclJHd1FWL5ETLklmdvNWLu9Wa0FmbpN2YhZ3L">
Suivant
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.137 8.424l-4.859 4.859a.6.6 0 01-.848 0l-.567-.567a.6.6 0 010-.847L8.712 8l-3.85-3.869a.6.6 0 010-.847l.567-.567a.6.6 0 01.848 0l4.859 4.859a.6.6 0 010 .848z"></path></svg>
</span>
</div>
</div>
"""
doc = html.document_fromstring(htmlString)
response = Response()
response._content = b'{}'
centers_page = CentersPage(browser=Browser(), response=response)
centers_page.doc = doc
next_page = centers_page.get_next_page()
assert next_page == 4
def test_get_next_page_fr_should_return_None_on_last_page(tmp_path):
"""
Check that get_next_page returns None when we are on the last page
"""
"""
Previous (data-u decoded): /vaccination-covid-19-autres-professions-prioritaires/france?page=7&ref_visit_motive_ids%5B%5D=6970&ref_visit_motive_ids%5B%5D=7005
"""
htmlString = """
<div class="next-previous-links">
<div class="previous dl-rounded-borders dl-white-bg">
<span data-u="=UDMwcTPEVTJCVTJzRWafVmdpR3bt9FdpNXa29lZlJnJwcTO20DR1UiQ
1Uyckl2XlZXa09WbfRXazlmdfZWZyZyN9U2ZhB3PlNmbhJnZvMXZylWY0lmc
vlmcw1ycu9WazNXZm9mcw1yclJHd1FWL5ETLklmdvNWLu9Wa0FmbpN2YhZ3L">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.863 7.576l4.859-4.859a.6.6 0 01.848 0l.567.567a.6.6 0 01.001.847L7.288 8l3.85 3.869a.6.6 0 01-.001.847l-.567.567a.6.6 0 01-.848 0L4.863 8.424a.6.6 0 010-.848z"></path></svg>
Précédent
</span>
</div>
<div class="next dl-rounded-borders dl-white-bg">
<span class="disabled">
Suivant
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.137 8.424l-4.859 4.859a.6.6 0 01-.848 0l-.567-.567a.6.6 0 010-.847L8.712 8l-3.85-3.869a.6.6 0 010-.847l.567-.567a.6.6 0 01.848 0l4.859 4.859a.6.6 0 010 .848z"></path></svg>
</span>
</div>
</div>
"""
doc = html.document_fromstring(htmlString)
response = Response()
response._content = b'{}'
centers_page = CentersPage(browser=Browser(), response=response)
centers_page.doc = doc
next_page = centers_page.get_next_page()
assert next_page == None
@responses.activate
def test_get_next_page_de_should_return_2_on_page_1(tmp_path):
"""
Check that get_next_page returns 2 when we are on page 1 and next page is available
"""
htmlString = """
<div class="next-previous-links">
<div class="previous dl-rounded-borders dl-white-bg">
<span class="disabled">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.863 7.576l4.859-4.859a.6.6 0 01.848 0l.567.567a.6.6 0 01.001.847L7.288 8l3.85 3.869a.6.6 0 01-.001.847l-.567.567a.6.6 0 01-.848 0L4.863 8.424a.6.6 0 010-.848z"></path></svg>
vorherige Seite
</span>
</div>
<div class="next dl-rounded-borders dl-white-bg">
<a href="/impfung-covid-19-corona/berlin?page=2&ref_visit_motive_ids%5B%5D=6769">
Nächste Seite
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.137 8.424l-4.859 4.859a.6.6 0 01-.848 0l-.567-.567a.6.6 0 010-.847L8.712 8l-3.85-3.869a.6.6 0 010-.847l.567-.567a.6.6 0 01.848 0l4.859 4.859a.6.6 0 010 .848z"></path></svg>
</a>
</div>
</div>
"""
doc = html.document_fromstring(htmlString)
response = Response()
response._content = b'{}'
centers_page = CentersPage(browser=Browser(), response=response)
centers_page.doc = doc
next_page = centers_page.get_next_page()
assert next_page == 2
@responses.activate
def test_get_next_page_de_should_return_3_on_page_2(tmp_path):
"""
Check that get_next_page returns 3 when we are on page 2 and next page is available
"""
htmlString = """
<div class="next-previous-links">
<div class="previous dl-rounded-borders dl-white-bg">
<a href="/impfung-covid-19-corona/berlin?ref_visit_motive_ids%5B%5D=6769">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.863 7.576l4.859-4.859a.6.6 0 01.848 0l.567.567a.6.6 0 01.001.847L7.288 8l3.85 3.869a.6.6 0 01-.001.847l-.567.567a.6.6 0 01-.848 0L4.863 8.424a.6.6 0 010-.848z"></path></svg>
vorherige Seite
</a>
</div>
<div class="next dl-rounded-borders dl-white-bg">
<a href="/impfung-covid-19-corona/berlin?page=3&ref_visit_motive_ids%5B%5D=6769">
Nächste Seite
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.137 8.424l-4.859 4.859a.6.6 0 01-.848 0l-.567-.567a.6.6 0 010-.847L8.712 8l-3.85-3.869a.6.6 0 010-.847l.567-.567a.6.6 0 01.848 0l4.859 4.859a.6.6 0 010 .848z"></path></svg>
</a>
</div>
</div>
"""
doc = html.document_fromstring(htmlString)
response = Response()
response._content = b'{}'
centers_page = CentersPage(browser=Browser(), response=response)
centers_page.doc = doc
next_page = centers_page.get_next_page()
assert next_page == 3
@responses.activate
def test_get_next_page_de_should_return_4_on_page_3(tmp_path):
"""
Check that get_next_page returns 4 when we are on page 3 and next page is available
"""
htmlString = """
<div class="next-previous-links">
<div class="previous dl-rounded-borders dl-white-bg">
<a href="/impfung-covid-19-corona/berlin?page=2&ref_visit_motive_ids%5B%5D=6769">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.863 7.576l4.859-4.859a.6.6 0 01.848 0l.567.567a.6.6 0 01.001.847L7.288 8l3.85 3.869a.6.6 0 01-.001.847l-.567.567a.6.6 0 01-.848 0L4.863 8.424a.6.6 0 010-.848z"></path></svg>
vorherige Seite
</a>
</div>
<div class="next dl-rounded-borders dl-white-bg">
<a href="/impfung-covid-19-corona/berlin?page=4&ref_visit_motive_ids%5B%5D=6769">
Nächste Seite
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.137 8.424l-4.859 4.859a.6.6 0 01-.848 0l-.567-.567a.6.6 0 010-.847L8.712 8l-3.85-3.869a.6.6 0 010-.847l.567-.567a.6.6 0 01.848 0l4.859 4.859a.6.6 0 010 .848z"></path></svg>
</a>
</div>
</div>
"""
doc = html.document_fromstring(htmlString)
response = Response()
response._content = b'{}'
centers_page = CentersPage(browser=Browser(), response=response)
centers_page.doc = doc
next_page = centers_page.get_next_page()
assert next_page == 4
def test_get_next_page_de_should_return_None_on_last_page(tmp_path):
"""
Check that get_next_page returns None when we are on the last page
"""
htmlString = """
<div class="next-previous-links">
<div class="previous dl-rounded-borders dl-white-bg">
<a href="/impfung-covid-19-corona/berlin?page=5&ref_visit_motive_ids%5B%5D=6769">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M4.863 7.576l4.859-4.859a.6.6 0 01.848 0l.567.567a.6.6 0 01.001.847L7.288 8l3.85 3.869a.6.6 0 01-.001.847l-.567.567a.6.6 0 01-.848 0L4.863 8.424a.6.6 0 010-.848z"></path></svg>
vorherige Seite
</a>
</div>
<div class="next dl-rounded-borders dl-white-bg">
<span class="disabled">
Nächste Seite
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M11.137 8.424l-4.859 4.859a.6.6 0 01-.848 0l-.567-.567a.6.6 0 010-.847L8.712 8l-3.85-3.869a.6.6 0 010-.847l.567-.567a.6.6 0 01.848 0l4.859 4.859a.6.6 0 010 .848z"></path></svg>
</span>
</div>
</div>
"""
doc = html.document_fromstring(htmlString)
response = Response()
response._content = b'{}'
centers_page = CentersPage(browser=Browser(), response=response)
centers_page.doc = doc
next_page = centers_page.get_next_page()
assert next_page == None
@responses.activate
def test_book_slots_should_succeed(tmp_path):
"""
Check that try_to_book calls all services successfully
"""
docto = DoctolibDE("[email protected]",
"1234", responses_dirname=tmp_path)
docto.BASEURL = "https://127.0.0.1"
docto.patient = {
"id": "patient-id",
"first_name": "Roger",
"last_name": "Phillibert"
}
mock_search_result_id = {
"searchResultId": 1234567
}
mock_search_result_id_escaped_json = escape(
json.dumps(mock_search_result_id, separators=(',', ':')))
responses.add(
responses.GET,
"https://127.0.0.1/impfung-covid-19-corona/K%C3%B6ln?ref_visit_motive_ids%5B%5D=6768&ref_visit_motive_ids%5B%5D=6769&ref_visit_motive_ids%5B%5D=6936&ref_visit_motive_ids%5B%5D=6937&ref_visit_motive_ids%5B%5D=7978&ref_visit_motive_ids%5B%5D=7109&ref_visit_motive_ids%5B%5D=7110&page=1",
status=200,
body="<div class='js-dl-search-results-calendar' data-props='{dataProps}'></div>".format(
dataProps=mock_search_result_id_escaped_json)
)
with open(FIXTURES_FOLDER + '/search_result.json') as json_file:
mock_search_result = json.load(json_file)
responses.add(
responses.GET,
"https://127.0.0.1/search_results/1234567.json?limit=4&ref_visit_motive_ids%5B%5D=6768&ref_visit_motive_ids%5B%5D=6769&ref_visit_motive_ids%5B%5D=6936&ref_visit_motive_ids%5B%5D=6937&ref_visit_motive_ids%5B%5D=7978&ref_visit_motive_ids%5B%5D=7109&ref_visit_motive_ids%5B%5D=7110&speciality_id=5494&search_result_format=json",
status=200,
body=json.dumps(mock_search_result)
)
with open(FIXTURES_FOLDER + '/doctor_response.json') as json_file:
mock_doctor_response = json.load(json_file)
responses.add(
responses.GET,
"https://127.0.0.1/allgemeinmedizin/koeln/dr-dre?insurance_sector=public",
status=200,
body=json.dumps(mock_doctor_response)
)
responses.add(
responses.GET,
"https://127.0.0.1/booking/dr-dre.json",
status=200,
body=json.dumps(mock_doctor_response)
)
with open(FIXTURES_FOLDER + '/availabilities.json') as json_file:
mock_availabilities = json.load(json_file)
responses.add(
responses.GET,
"https://127.0.0.1/availabilities.json?start_date=2021-06-01&visit_motive_ids=2920448&agenda_ids=&insurance_sector=public&practice_ids=234567&destroy_temporary=true&limit=3",
status=200,
body=json.dumps(mock_availabilities)
)
responses.add(
responses.GET,
"https://127.0.0.1/availabilities.json?start_date=2021-06-01&visit_motive_ids=2746983&agenda_ids=&insurance_sector=public&practice_ids=234567&destroy_temporary=true&limit=3",
status=200,
body=json.dumps(mock_availabilities)
)
mock_appointments = {
"id": "appointment-id"
}
responses.add(
responses.POST,
"https://127.0.0.1/appointments.json",
status=200,
body=json.dumps(mock_appointments)
)
mock_appointments_edit = {
"id": "appointment-edit-id",
"appointment": {
"custom_fields": {}
}
}
responses.add(
responses.GET,
"https://127.0.0.1/appointments/appointment-id/edit.json",
status=200,
body=json.dumps(mock_appointments_edit)
)
responses.add(
responses.GET,
"https://127.0.0.1/second_shot_availabilities.json?start_date=2021-07-20&visit_motive_ids=2746983&agenda_ids=&first_slot=2021-06-10T08%3A40%3A00.000%2B02%3A00&insurance_sector=public&practice_ids=234567&limit=3",
status=200,
body=json.dumps(mock_availabilities)
)
mock_appointment_id_put = {
}
responses.add(
responses.PUT,
"https://127.0.0.1/appointments/appointment-id.json",
status=200,
body=json.dumps(mock_appointment_id_put)
)
mock_appointment_id = {
"confirmed": True
}
responses.add(
responses.GET,
"https://127.0.0.1/appointments/appointment-id.json",
status=200,
body=json.dumps(mock_appointment_id)
)
result_handled = False
for result in docto.find_centers(["Köln"]):
result_handled = True
center = result['search_result']
# single shot vaccination
assert docto.try_to_book(center=center,
vaccine_list=["Janssen"],
start_date=datetime.date(
year=2021, month=6, day=1),
end_date=datetime.date(
year=2021, month=6, day=14),
only_second=False,
only_third=False,
dry_run=False)
assert len(responses.calls) == 10
# two shot vaccination
assert docto.try_to_book(center=center,
vaccine_list=["Pfizer"],
start_date=datetime.date(
year=2021, month=6, day=1),
end_date=datetime.date(
year=2021, month=6, day=14),
only_second=False,
only_third=False,
dry_run=False)
assert len(responses.calls) == 20
pass
assert result_handled
@responses.activate
def test_find_motive_should_ignore_second_shot(tmp_path):
"""
Check that find_motive ignores second shot motives
"""
with open(FIXTURES_FOLDER + '/doctor_response.json') as json_file:
mock_doctor_response = json.load(json_file)
response = Response()
response._content = b'{}'
booking_page = CenterBookingPage(browser=Browser(), response=response)
booking_page.doc = mock_doctor_response
visit_motive_id = CenterBookingPage.find_motive(
booking_page, '.*(Pfizer)', False)
assert visit_motive_id == mock_doctor_response['data']['visit_motives'][1]['id']
visit_motive_id = CenterBookingPage.find_motive(
booking_page, '.*(Janssen)', True)
assert visit_motive_id == mock_doctor_response['data']['visit_motives'][3]['id']