-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_views.py
3222 lines (2507 loc) · 101 KB
/
test_views.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
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import onegov.feriennet
import os
import pytest
import re
import requests_mock
import transaction
from datetime import datetime, timedelta, date, time
from freezegun import freeze_time
from onegov.activity import Booking, Invoice, InvoiceItem
from onegov.activity.utils import generate_xml
from onegov.core.custom import json
from onegov.feriennet.utils import NAME_SEPARATOR
from onegov.file import FileCollection
from onegov.gis import Coordinates
from onegov.pay import Payment
from psycopg2.extras import NumericRange
from sedate import utcnow
from tests.shared import utils
from unittest.mock import patch
from webtest import Upload
def test_wwf_fixed_pass_system(client, scenario):
scenario.add_period(
title='WWF Period',
phase='wishlist',
active=True,
confirmable=True,
finalizable=True,
)
# Add booking user
scenario.add_user(
username='[email protected]',
role='member',
complete_profile=True
)
scenario.add_attendee(name='George', username='[email protected]')
# Add activities
tags = ['Familienlager', 'Ferienlager']
scenario.add_activity(title='Surfing', state='accepted', tags=[tags[1]])
scenario.add_occasion(cost=250)
scenario.add_activity(title='Sailing', state='accepted', tags=[tags[1]])
scenario.add_occasion(cost=500)
scenario.add_activity(title='Fishing', state='accepted', tags=[tags[0]])
scenario.add_occasion(cost=50)
scenario.commit()
scenario.refresh()
admin = client
admin.login_admin()
# Edit the period
fixed_system_limit = 1
page = admin.get('/periods').click('Bearbeiten')
page.form['pass_system'] = 'fixed'
page.form['fixed_system_limit'] = fixed_system_limit
page.form['single_booking_cost'] = 11
page.form.submit().follow()
scenario.refresh()
period = scenario.latest_period
booking_start = period.booking_start
assert period.all_inclusive is False
assert period.max_bookings_per_attendee == 1
assert period.booking_cost == 11
assert period.pay_organiser_directly is False
def login_member(client):
login = client.get('/').click("Anmelden", index=1)
login.form['username'] = '[email protected]'
login.form['password'] = 'hunter2'
login.form.submit().follow()
return client
member = login_member(client.spawn())
activities = member.get('/activities')
def register_for_activity(name):
# Register the first attendee available
page = activities.click(name).click('Anmelden').form.submit().follow()
assert 'Durchführung wurde zu Georges Wunschliste hinzugefügt' in page
return page
register_for_activity('Sailing')
page = register_for_activity('Fishing')
# We check his wishlist
wishlist = page.click('Wunschliste')
# We do not want a link to the limit view of the attendee
assert not wishlist.pyquery('div.booking-limit a')
book_limit_text = wishlist.pyquery('div.booking-limit span')[0].text
assert book_limit_text == f'Limitiert auf {fixed_system_limit} Buchungen'
page = admin.get('/matching')
page.form['confirm'] = 'yes'
page.form['sure'] = 'y'
page = page.form.submit()
assert 'Die Zuteilung wurde erfolgreich abgeschlossen' in page
# confirm period, proceed to booking phase
with freeze_time(booking_start + timedelta(days=1)):
page = member.get('/my-bookings')
assert 'Die Buchungsphase ist jetzt bis am' in page
assert 'Gebucht (1)' in page
assert 'Blockiert (1)' in page
def test_view_permissions():
utils.assert_explicit_permissions(
onegov.feriennet, onegov.feriennet.FeriennetApp)
def test_view_hint_max_activities(client, scenario):
client.login_admin()
scenario.add_period(
title='Testperiod',
active=True,
confirmable=True,
finalizable=True,
max_bookings_per_attendee=4,
)
scenario.commit()
scenario.refresh()
page = client.get('/')
page = page.click('Wunschliste')
assert "Teilnehmende werden in bis zu 4 Angebot(e) eingeteilt." in page
assert "bis zu 4 Angebot(e) angemeldet werden." not in page
period_settings = client.get('/periods')
period_settings.click('Deaktivieren')
scenario.add_period(
title='Testperiod2',
active=True,
confirmable=False,
finalizable=True,
max_bookings_per_attendee=4,
)
scenario.commit()
scenario.refresh()
page = client.get('/')
page = page.click('Wunschliste')
assert "bis zu 4 Angebot(e) angemeldet werden." in page
assert "Teilnehmende werden in bis zu 4 Angebot(e) eingeteilt." not in page
def test_activity_permissions(client, scenario):
anon = client.spawn()
admin = client.spawn()
editor = client.spawn()
admin.login_admin()
editor.login_editor()
scenario.add_period()
scenario.add_activity(
title="Learn How to Program",
username='[email protected]'
)
scenario.add_occasion()
scenario.commit()
url = '/activity/learn-how-to-program'
assert "Learn How to Program" in editor.get('/activities')
assert "Learn How to Program" not in anon.get('/activities')
assert "Learn How to Program" in admin.get('/activities')
assert "Learn How to Program" not in anon.get('/activities/json')
assert "Learn How to Program" not in editor.get('/activities/json')
assert "Learn How to Program" not in admin.get('/activities/json')
assert editor.get(url, status=200)
assert anon.get(url, status=404)
assert admin.get(url, status=200)
editor.get(url).click("Publikation beantragen")
assert "Learn How to Program" in editor.get('/activities')
assert "Learn How to Program" not in anon.get('/activities')
assert "Learn How to Program" in admin.get('/activities')
assert "Learn How to Program" not in anon.get('/activities/json')
assert "Learn How to Program" not in editor.get('/activities/json')
assert "Learn How to Program" not in admin.get('/activities/json')
assert editor.get(url, status=200)
assert anon.get(url, status=404)
ticket = admin.get('/tickets/ALL/open').click("Annehmen").follow()
ticket.click("Veröffentlichen")
assert "Learn How to Program" in editor.get('/activities')
assert "Learn How to Program" in anon.get('/activities')
assert "Learn How to Program" in admin.get('/activities')
assert "Learn How to Program" in anon.get('/activities/json')
assert "Learn How to Program" in editor.get('/activities/json')
assert "Learn How to Program" in admin.get('/activities/json')
assert editor.get(url, status=200)
assert anon.get(url, status=200)
assert admin.get(url, status=200)
ticket = admin.get(ticket.request.url)
ticket.click("Archivieren")
assert "Learn How to Program" in editor.get('/activities')
assert "Learn How to Program" not in anon.get('/activities')
assert "Learn How to Program" in admin.get('/activities')
assert "Learn How to Program" not in anon.get('/activities/json')
assert "Learn How to Program" not in editor.get('/activities/json')
assert "Learn How to Program" not in admin.get('/activities/json')
assert editor.get(url, status=200)
assert anon.get(url, status=404)
assert admin.get(url, status=200)
@patch('onegov.websockets.integration.connect')
@patch('onegov.websockets.integration.authenticate')
@patch('onegov.websockets.integration.broadcast')
def test_activity_communication(broadcast, authenticate, connect, client,
scenario):
scenario.add_period()
scenario.add_activity(
title="Learn Python",
lead="Using a Raspberry Pi we will learn Python",
username='[email protected]'
)
scenario.add_occasion()
scenario.commit()
admin = client.spawn()
admin.login_admin()
editor = client.spawn()
editor.login_editor()
editor.get('/activity/learn-python').click("Publikation beantragen")
assert len(os.listdir(client.app.maildir)) == 1
assert "Ihre Anfrage wurde unter der " \
"folgenden Referenz registriert" in admin.get_email(0)['HtmlBody']
assert connect.call_count == 1
assert authenticate.call_count == 1
assert broadcast.call_count == 1
assert broadcast.call_args[0][3]['event'] == 'browser-notification'
assert broadcast.call_args[0][3]['title'] == 'Neues Ticket'
assert broadcast.call_args[0][3]['created']
ticket = admin.get('/tickets/ALL/open').click("Annehmen").follow()
assert "Learn Python" in ticket
ticket.click("Veröffentlichen")
assert len(os.listdir(client.app.maildir)) == 2
message = admin.get_email(1)['TextBody']
assert "wurde veröffentlicht" in message
assert "Learn Python" in message
assert "Using a Raspberry Pi we will learn Python" in message
def test_activity_search(client_with_es, scenario):
client = client_with_es
scenario.add_period()
scenario.add_activity(
title="Learn How to Program",
lead="Using a Raspberry Pi we will learn Python",
username='[email protected]'
)
scenario.add_occasion()
scenario.commit()
admin = client.spawn()
admin.login_admin()
editor = client.spawn()
editor.login_editor()
# in preview, activities can't be found
client.app.es_client.indices.refresh(index='_all')
assert 'search-result-vacation' not in admin.get('/search?q=Learn')
assert 'search-result-vacation' not in editor.get('/search?q=Learn')
assert 'search-result-vacation' not in client.get('/search?q=Learn')
url = '/activity/learn-how-to-program'
editor.get(url).click("Publikation beantragen")
# once proposed, activities can be found by the admin only
client.app.es_client.indices.refresh(index='_all')
assert 'search-result-vacation' in admin.get('/search?q=Learn')
assert 'search-result-vacation' not in editor.get('/search?q=Learn')
assert 'search-result-vacation' not in client.get('/search?q=Learn')
ticket = admin.get('/tickets/ALL/open').click("Annehmen").follow()
ticket.click("Veröffentlichen")
# once accepted, activities can be found by anyone
client.app.es_client.indices.refresh(index='_all')
assert 'search-result-vacation' in admin.get('/search?q=Learn')
assert 'search-result-vacation' in editor.get('/search?q=Learn')
assert 'search-result-vacation' in client.get('/search?q=Learn')
ticket = admin.get(ticket.request.url)
ticket.click("Archivieren")
# archived the search will fail again, except for admins
client.app.es_client.indices.refresh(index='_all')
assert 'search-result-vacation' in admin.get('/search?q=Learn')
assert 'search-result-vacation' not in editor.get('/search?q=Learn')
assert 'search-result-vacation' not in client.get('/search?q=Learn')
def test_activity_filter_tags(client, scenario):
scenario.add_period(
prebooking_start=datetime(2015, 1, 1),
prebooking_end=datetime(2015, 12, 31),
booking_start=datetime(2015, 12, 31),
booking_end=datetime(2015, 12, 31),
execution_start=datetime(2016, 1, 1),
execution_end=datetime(2016, 12, 31)
)
scenario.add_activity(
title="Learn How to Program",
lead="Using a Rasperry Pi we will learn Python",
tags=['Computer', 'Science'],
username='[email protected]'
).propose().accept()
scenario.add_activity(
title="Learn How to Cook",
lead="Using a Stove we will cook a Python",
tags=['Cooking', 'Science'],
username='[email protected]'
).propose().accept()
scenario.commit()
editor = client.spawn()
editor.login_editor()
admin = client.spawn()
admin.login_admin()
# only show activites to anonymous if there's an active period..
page = client.get('/activities')
assert "Keine Angebote" in page
# ..and if there are any occasions for those activities
with scenario.update():
for activity in scenario.activities:
scenario.add_occasion(
activity=activity,
start=datetime(2016, 1, 1, 10),
end=datetime(2016, 1, 1, 18)
)
page = client.get('/activities')
assert "Learn How to Cook" in page
assert "Learn How to Program" in page
page = page.click('Computer')
assert "Learn How to Cook" not in page
assert "Learn How to Program" in page
page = page.click('Computer')
assert "Learn How to Cook" in page
assert "Learn How to Program" in page
page = page.click('Kochen')
assert "Learn How to Cook" in page
assert "Learn How to Program" not in page
page = page.click('Computer')
assert "Learn How to Cook" in page
assert "Learn How to Program" in page
page = page.click('Computer')
page = page.click('Kochen')
page = page.click('Wissenschaft')
assert "Learn How to Cook" in page
assert "Learn How to Program" in page
# the state filter works for editors
new = editor.get('/activities').click("Angebot erfassen")
new.form['title'] = "Learn How to Dance"
new.form['lead'] = "We will dance with a Python"
new.form.submit()
# editors see the state as a filter
assert "Vorschau" in editor.get('/activities')
# anonymous does not
assert "Vorschau" not in client.get('/activities')
page = editor.get('/activities').click('Vorschau')
assert "Learn How to Cook" not in page
assert "Learn How to Program" not in page
assert "Learn How to Dance" in page
# anyone can filter by week, only weeks with activites are shown
assert "04.01.2016 - 10.01.2016" not in page
assert "01.01.2016 - 03.01.2016" in page
page = editor.get('/activities').click('01.01.2016 - 03.01.2016', index=0)
assert "Learn How to Cook" in page
def test_activity_filter_duration(client, scenario):
scenario.add_period()
# the retreat lasts a weekend
scenario.add_activity(title="Retreat", state='accepted')
scenario.add_occasion(
start=datetime(2016, 10, 8, 8),
end=datetime(2016, 10, 9, 16),
)
# the meeting lasts half a day
scenario.add_activity(title="Meeting", state='accepted')
scenario.add_occasion(
start=datetime(2016, 10, 10, 8),
end=datetime(2016, 10, 10, 12),
)
scenario.commit()
half_day = client.get('/activities').click('Halbtägig')
many_day = client.get('/activities').click('Mehrtägig')
assert "Meeting" in half_day
assert "Retreat" not in half_day
assert "Meeting" not in many_day
assert "Retreat" in many_day
# shorten the retreat
with scenario.update():
scenario.occasions[0].dates[0].end -= timedelta(days=1)
full_day = client.get('/activities').click('Ganztägig')
many_day = client.get('/activities').click('Mehrtägig')
assert "Retreat" in full_day
assert "Retreat" not in many_day
def test_activity_filter_weeks(client, scenario):
scenario.add_period(
prebooking_start=datetime(2022, 2, 1),
prebooking_end=datetime(2022, 2, 28),
booking_start=datetime(2022, 3, 1),
booking_end=datetime(2022, 3, 31),
execution_start=datetime(2022, 4, 1),
execution_end=datetime(2022, 4, 30)
)
scenario.add_activity(title="Camping", state='accepted')
scenario.add_occasion(
start=datetime(2022, 4, 4, 8),
end=datetime(2022, 4, 21, 12),
)
scenario.commit()
page = client.get('/activities')
# test if all weeks are in the filter, not just the first
assert "04.04.2022 - 10.04.2022" in page
assert "11.04.2022 - 17.04.2022" in page
assert "18.04.2022 - 24.04.2022" in page
def test_activity_filter_age_ranges(client, scenario):
scenario.add_period()
# the retreat is for really young kids
scenario.add_activity(title="Retreat", state='accepted')
scenario.add_occasion(age=(0, 10))
# the meeting is for young to teenage kids
scenario.add_activity(title="Meeting", state='accepted')
scenario.add_occasion(age=(5, 15))
scenario.commit()
preschool = client.get('/activities').click(
'5', href='filter=age', index=0)
highschool = client.get('/activities').click(
'15', href='filter=age', index=0)
assert "Retreat" in preschool
assert "Meeting" in preschool
assert "Retreat" not in highschool
assert "Meeting" in highschool
# change the meeting age
with scenario.update():
scenario.occasions[1].age = NumericRange(15, 20)
preschool = client.get('/activities').click(
'5', href='filter=age', index=0)
assert "Retreat" in preschool
assert "Meeting" not in preschool
def test_organiser_info(client, scenario):
admin = client.spawn()
admin.login_admin()
editor = client.spawn()
editor.login_editor()
scenario.add_period()
scenario.add_activity(
title="Play with Legos",
state='accepted',
username='[email protected]'
)
scenario.add_activity(
title="Play with Playmobil",
state='accepted',
username='[email protected]'
)
scenario.commit()
# by default no information is shown
for id in ('play-with-legos', 'play-with-playmobil'):
# except the name, which is already set in the test scenario
assert len(editor.get(f'/activity/{id}').pyquery('.organiser li')) == 1
assert len(admin.get(f'/activity/{id}').pyquery('.organiser li')) == 1
# owner changes are reflected on the activity
contact = editor.get('/userprofile')
contact.form['salutation'] = 'mr'
contact.form['first_name'] = 'Ed'
contact.form['last_name'] = 'Itor'
contact.form['organisation'] = 'Editors Association'
contact.form['address'] = 'K Street'
contact.form['zip_code'] = '20001'
contact.form['place'] = 'Washington'
contact.form['email'] = '[email protected]'
contact.form['phone'] = '+41234567890'
contact.form['website'] = 'https://www.example.org'
contact.form['emergency'] = '+01 234 56 78 (Peter)'
contact.form.submit()
activity = editor.get('/activity/play-with-legos')
assert "Editors Association" in activity
assert "Ed\u00A0Itor" in activity
assert "Washington" not in activity
assert "20001" not in activity
assert "K Street" not in activity
assert "[email protected]" not in activity
assert "+41 23 456 789" not in activity
assert "https://www.example.org" in activity
# admin changes are reflected on the activity
contact = admin.get('/usermanagement')\
.click('Veranstalter')\
.click('Ansicht')\
.click('Bearbeiten')
contact.form['organisation'] = 'Admins Association'
contact.form.submit()
activity = editor.get('/activity/play-with-legos')
assert "Admins Association" in activity
# we can show/hide information individually
def with_public_organiser_data(values):
page = admin.get('/feriennet-settings')
page.form['public_organiser_data'] = values
page.form.submit()
return editor.get('/activity/play-with-legos')
page = with_public_organiser_data([])
assert 'Veranstalter' not in page
page = with_public_organiser_data(['name'])
assert "Admins Association" in page
assert "Washington" not in page
assert "[email protected]" not in page
assert "+41 23 456 789" not in page
assert "https://www.example.org" not in page
page = with_public_organiser_data(['address'])
assert "Admins Association" not in page
assert "Washington" in page
assert "[email protected]" not in page
assert "+41 23 456 78 90" not in page
assert "https://www.example.org" not in page
page = with_public_organiser_data(['email'])
assert "Admins Association" not in page
assert "Washington" not in page
assert "[email protected]" in page
assert "+41 23 456 78 90" not in page
assert "https://www.example.org" not in page
page = with_public_organiser_data(['phone'])
assert "Admins Association" not in page
assert "Washington" not in page
assert "[email protected]" not in page
assert "+41 23 456 78 90" in page
assert "https://www.example.org" not in page
page = with_public_organiser_data(['website'])
assert "Admins Association" not in page
assert "Washington" not in page
assert "[email protected]" not in page
assert "+41 23 456 78 90" not in page
assert "https://www.example.org" in page
def test_occasions_form(client, scenario):
editor = client.spawn()
editor.login_editor()
admin = client.spawn()
admin.login_admin()
scenario.add_period(
prebooking_start=date(2016, 9, 1),
prebooking_end=date(2016, 9, 30),
booking_start=date(2016, 9, 30),
booking_end=date(2016, 9, 30),
execution_start=date(2016, 10, 1),
execution_end=date(2016, 10, 31),
)
scenario.add_activity(
title="Play with Legos",
username='[email protected]'
)
scenario.commit()
activity = editor.get('/activities').click("Play with Legos")
assert "keine Durchführungen" in activity
occasion = activity.click("Neue Durchführung")
occasion.form['dates'] = json.dumps({
'values': [{
'start': '2016-10-04 10:00:00',
'end': '2016-10-04 12:00:00'
}]
})
# test submitting empty, form ensurances must cope with missing data
occasion.form.submit()
occasion.form['meeting_point'] = "Franz Karl Weber"
occasion.form['note'] = "No griefers"
occasion.form['min_age'] = 10
occasion.form['max_age'] = 20
occasion.form['min_spots'] = 30
occasion.form['max_spots'] = 40
activity = occasion.form.submit().follow()
assert "keine Durchführungen" not in activity
assert "4. Oktober 10:00 - 12:00" in activity
assert "10 - 20 Jahre" in activity
assert "30 - 40 Teilnehmende" in activity
assert "Franz Karl Weber" in activity
assert "No griefers" in activity
occasion = activity.click("Bearbeiten", index=1)
occasion.form['min_age'] = 15
activity = occasion.form.submit().follow()
assert "15 - 20 Jahre" in activity
occasion = activity.click("Duplizieren")
occasion.form['min_age'] = 10
occasion.form['dates'] = json.dumps({
'values': [{
'start': '2016-10-04 13:00:00',
'end': '2016-10-04 15:00:00'
}]
})
activity = occasion.form.submit().follow()
assert "15 - 20 Jahre" in activity
assert "10 - 20 Jahre" in activity
activity.click("Löschen", index=0)
activity.click("Löschen", index=1)
assert "keine Durchführungen" in editor.get('/activity/play-with-legos')
def test_multiple_dates_occasion(client, scenario):
editor = client.spawn()
editor.login_editor()
admin = client.spawn()
admin.login_admin()
scenario.add_period(
prebooking_start=date(2016, 9, 1),
prebooking_end=date(2016, 9, 30),
booking_start=date(2016, 9, 30),
booking_end=date(2016, 9, 30),
execution_start=date(2016, 10, 1),
execution_end=date(2016, 10, 31),
)
scenario.add_activity(
title="Play with Legos",
username='[email protected]'
)
scenario.commit()
activity = editor.get('/activities').click("Play with Legos")
assert "keine Durchführungen" in activity
occasion = activity.click("Neue Durchführung")
occasion.form['meeting_point'] = "Franz Karl Weber"
occasion.form['note'] = "No griefers"
occasion.form['min_age'] = 10
occasion.form['max_age'] = 20
occasion.form['min_spots'] = 30
occasion.form['max_spots'] = 40
occasion.form['dates'] = ""
assert "mindestens ein Datum" in occasion.form.submit()
occasion.form['dates'] = json.dumps({
'values': [{
'start': '2016-10-04 10:00:00',
'end': '2016-10-04 12:00:00'
}, {
'start': '2016-10-04 10:00:00',
'end': '2016-10-04 12:00:00'
}]
})
assert "mit einem anderen Datum" in occasion.form.submit()
occasion.form['dates'] = json.dumps({
'values': [{
'start': '2016-10-01 10:00:00',
'end': '2016-10-01 12:00:00'
}, {
'start': '2016-10-02 10:00:00',
'end': '2016-10-02 12:00:00'
}]
})
activity = occasion.form.submit().follow()
assert "1. Oktober 10:00" in activity
assert "2. Oktober 10:00" in activity
def test_execution_period(client, scenario):
admin = client.spawn()
admin.login_admin()
scenario.add_period(
prebooking_start=date(2016, 9, 1),
prebooking_end=date(2016, 9, 30),
booking_start=date(2016, 9, 30),
booking_end=date(2016, 9, 30),
execution_start=date(2016, 10, 1),
execution_end=date(2016, 10, 1),
)
scenario.add_activity(
title="Play with Lego",
username='[email protected]'
)
scenario.commit()
occasion = admin.get('/activity/play-with-lego').click("Neue Durchführung")
occasion.form['min_age'] = 10
occasion.form['max_age'] = 20
occasion.form['min_spots'] = 30
occasion.form['max_spots'] = 40
occasion.form['meeting_point'] = 'At the venue'
occasion.form['dates'] = json.dumps({
'values': [{
'start': '2016-10-01 00:00:00',
'end': '2016-10-02 23:59:59'
}]
})
assert "Datum liegt ausserhalb" in occasion.form.submit()
occasion.form['dates'] = json.dumps({
'values': [{
'start': '2016-09-30 00:00:00',
'end': '2016-10-01 23:59:59'
}]
})
assert "Datum liegt ausserhalb" in occasion.form.submit()
occasion.form['dates'] = json.dumps({
'values': [{
'start': '2016-10-01 00:00:00',
'end': '2016-10-01 23:59:59'
}]
})
assert "Änderungen wurden gespeichert" in occasion.form.submit().follow()
period = admin.get('/periods').click("Bearbeiten")
period.form['execution_start'] = '2016-10-02'
period.form['execution_end'] = '2016-10-02'
period = period.form.submit()
assert "in Konflikt" in period
assert "Play with Lego" in period
period.form['execution_start'] = '2016-10-01'
period.form['execution_end'] = '2016-10-01'
periods = period.form.submit().follow()
assert "gespeichert" in periods
@pytest.mark.skip_night_hours
def test_enroll_child(client, scenario):
scenario.add_period(
prebooking_end=scenario.date_offset(0)
)
scenario.add_activity(title="Retreat", state='accepted')
scenario.add_occasion()
scenario.add_user(
username='[email protected]',
role='member',
complete_profile=False
)
scenario.commit()
activity = client.get('/activity/retreat')
login = activity.click("Anmelden", index=1)
login.form['username'] = '[email protected]'
login.form['password'] = 'hunter2'
enroll = login.form.submit().follow()
assert "Ihr Benutzerprofil ist unvollständig" in enroll
# now that we're logged in, the login link automatically skips ahead
enroll = activity.click("Anmelden", index=1).follow()
assert "Teilnehmende anmelden" in enroll
# the link changes, but the result stays the same
enroll = client.get('/activity/retreat').click("Anmelden")
assert "Teilnehmende anmelden" in enroll
enroll.form['first_name'] = "Tom"
enroll.form['last_name'] = "Sawyer"
enroll.form['birth_date'] = "2012-01-01"
enroll.form['gender'] = 'male'
enroll = enroll.form.submit()
# before continuing, the user needs to fill his profile
assert "Ihr Benutzerprofil ist unvollständig" in enroll
client.fill_out_profile()
activity = enroll.form.submit().follow()
assert "zu Tom\u00A0Sawyers Wunschliste hinzugefügt" in activity
# prevent double-subscriptions
enroll = activity.click("Anmelden")
assert "Tom\u00A0Sawyer hat sich bereits für diese Durchführung"\
in enroll.form.submit()
enroll.form['attendee'] = 'other'
enroll.form['first_name'] = "Tom"
enroll.form['last_name'] = "Sawyer"
enroll.form['birth_date'] = "2011-01-01"
enroll.form['gender'] = 'male'
# prevent adding two kids with the same name
assert "Sie haben bereits eine Person mit diesem Namen erfasst"\
in enroll.form.submit()
# prevent enrollment for inactive periods
with scenario.update():
scenario.latest_period.active = False
enroll.form['first_name'] = "Huckleberry"
enroll.form['last_name'] = "Finn"
assert "Diese Durchführung liegt ausserhalb des aktiven Zeitraums"\
in enroll.form.submit()
# prevent enrollment outside of prebooking
with scenario.update():
scenario.latest_period.active = True
scenario.latest_period.prebooking_start -= timedelta(days=10)
scenario.latest_period.prebooking_end -= timedelta(days=10)
assert "nur während der Wunschphase" in enroll.form.submit()
# set the record straight again and test it on the edge
with scenario.update():
scenario.latest_period.prebooking_start += timedelta(days=10)
scenario.latest_period.prebooking_end += timedelta(days=10)
enroll.form['first_name'] = "Huckleberry"
enroll.form['last_name'] = "Finn"
activity = enroll.form.submit().follow()
assert "zu Huckleberry\u00A0Finns Wunschliste hinzugefügt" in activity
# prevent booking over the limit
with scenario.update():
scenario.latest_period.all_inclusive = True
scenario.latest_period.max_bookings_per_attendee = 1
scenario.latest_period.confirm_and_start_booking_phase()
scenario.add_activity(title="Another Retreat", state='accepted')
scenario.add_occasion()
enroll = client.get('/activity/another-retreat').click("Anmelden")
enroll.form.submit()
assert "maximale Anzahl von 1 Buchungen" in enroll.form.submit()
def test_enroll_age_mismatch(client, scenario):
scenario.add_period()
scenario.add_activity(title="Retreat", state='accepted')
scenario.add_occasion(age=(5, 10))
scenario.commit()
admin = client.spawn()
admin.login_admin()
admin.fill_out_profile()
page = admin.get('/activity/retreat').click("Anmelden")
page.form['first_name'] = "Tom"
page.form['last_name'] = "Sawyer"
page.form['gender'] = 'male'
page.form['birth_date'] = "1900-01-01"
assert "zu alt" in page.form.submit()
page.form['birth_date'] = f"{date.today().year - 3}-01-01"
assert "zu jung" in page.form.submit()
page.form['ignore_age'] = True
assert "Wunschliste hinzugefügt" in page.form.submit().follow()
def test_enroll_after_wishlist_phase(client, scenario):
scenario.add_period()
scenario.add_activity(title="Retreat", state='accepted')
scenario.add_occasion()
scenario.commit()
admin = client.spawn()
admin.login_admin()
admin.fill_out_profile()
page = admin.get('/activity/retreat').click("Anmelden")
page.form['first_name'] = "Tom"
page.form['last_name'] = "Sawyer"
page.form['gender'] = 'male'
page.form['birth_date'] = "2015-01-01"
page.form['ignore_age'] = True
with freeze_time(datetime.now() + timedelta(days=2)):
assert "nur während der Wunschphase" in page.form.submit()
def test_booking_view(client, scenario):
scenario.add_period(title="2017", active=False)
scenario.add_period(title="2016", active=True)
for i in range(4):
scenario.add_activity(title=f"A {i}", state='accepted')
scenario.add_occasion()
scenario.add_user(username='[email protected]', role='member', realname="Tom")
scenario.add_attendee(
name="Dustin",
birth_date=date(2000, 1, 1)
)
scenario.add_user(username='[email protected]', role='member', realname="Doc")
scenario.add_attendee(
name="Mike",
birth_date=date(2000, 1, 1)
)