5 |
5 |
import pytest
|
6 |
6 |
from django.template import Context
|
7 |
7 |
from django.test.client import RequestFactory
|
8 |
|
from django.utils.timezone import make_aware, now
|
|
8 |
from django.utils.timezone import make_aware
|
9 |
9 |
from publik_django_templatetags.wcs.context_processors import Cards
|
10 |
10 |
|
11 |
11 |
from lingo.agendas.models import Agenda, CheckType, CheckTypeGroup
|
... | ... | |
26 |
26 |
PricingMatrixCell,
|
27 |
27 |
PricingMatrixRow,
|
28 |
28 |
PricingMultipleBookingError,
|
29 |
|
PricingSubscriptionError,
|
|
29 |
PricingUnknownCheckStatusError,
|
30 |
30 |
)
|
31 |
31 |
|
32 |
32 |
pytestmark = pytest.mark.django_db
|
... | ... | |
222 |
222 |
assert new_pricing.slug == 'bar'
|
223 |
223 |
|
224 |
224 |
|
225 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
226 |
225 |
def test_get_agenda_pricing():
|
227 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
226 |
agenda = Agenda.objects.create(label='Foo bar')
|
228 |
227 |
pricing = Pricing.objects.create(label='Foo bar')
|
229 |
|
event = Event.objects.create(
|
230 |
|
agenda=agenda, start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)), places=10
|
231 |
|
)
|
|
228 |
event = {
|
|
229 |
'start_datetime': make_aware(datetime.datetime(2021, 9, 15, 12, 00)).isoformat(),
|
|
230 |
}
|
232 |
231 |
|
233 |
232 |
# not found
|
234 |
233 |
with pytest.raises(AgendaPricingNotFound):
|
235 |
|
AgendaPricing.get_agenda_pricing(event)
|
|
234 |
AgendaPricing.get_agenda_pricing(agenda=agenda, event=event)
|
236 |
235 |
|
237 |
236 |
# ok
|
238 |
237 |
agenda_pricing = AgendaPricing.objects.create(
|
... | ... | |
241 |
240 |
date_start=datetime.date(year=2021, month=9, day=1),
|
242 |
241 |
date_end=datetime.date(year=2021, month=10, day=1),
|
243 |
242 |
)
|
244 |
|
assert AgendaPricing.get_agenda_pricing(event) == agenda_pricing
|
|
243 |
assert AgendaPricing.get_agenda_pricing(agenda=agenda, event=event) == agenda_pricing
|
245 |
244 |
|
246 |
245 |
# more than one matching
|
247 |
246 |
AgendaPricing.objects.create(
|
... | ... | |
251 |
250 |
date_end=datetime.date(year=2021, month=9, day=16),
|
252 |
251 |
)
|
253 |
252 |
with pytest.raises(AgendaPricingNotFound):
|
254 |
|
AgendaPricing.get_agenda_pricing(event)
|
|
253 |
AgendaPricing.get_agenda_pricing(agenda=agenda, event=event)
|
255 |
254 |
|
256 |
255 |
|
257 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
258 |
256 |
@pytest.mark.parametrize(
|
259 |
257 |
'event_date, found',
|
260 |
258 |
[
|
... | ... | |
269 |
267 |
],
|
270 |
268 |
)
|
271 |
269 |
def test_get_agenda_pricing_event_date(event_date, found):
|
272 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
|
270 |
agenda = Agenda.objects.create(label='Foo bar')
|
273 |
271 |
pricing = Pricing.objects.create(label='Foo bar')
|
274 |
|
event = Event.objects.create(
|
275 |
|
agenda=agenda, start_datetime=make_aware(datetime.datetime(*event_date)), places=10
|
276 |
|
)
|
|
272 |
event = {
|
|
273 |
'start_datetime': make_aware(datetime.datetime(*event_date)).isoformat(),
|
|
274 |
}
|
277 |
275 |
agenda_pricing = AgendaPricing.objects.create(
|
278 |
276 |
agenda=agenda,
|
279 |
277 |
pricing=pricing,
|
... | ... | |
281 |
279 |
date_end=datetime.date(year=2021, month=10, day=1),
|
282 |
280 |
)
|
283 |
281 |
if found:
|
284 |
|
assert AgendaPricing.get_agenda_pricing(event) == agenda_pricing
|
|
282 |
assert AgendaPricing.get_agenda_pricing(agenda=agenda, event=event) == agenda_pricing
|
285 |
283 |
else:
|
286 |
284 |
with pytest.raises(AgendaPricingNotFound):
|
287 |
|
AgendaPricing.get_agenda_pricing(event)
|
|
285 |
AgendaPricing.get_agenda_pricing(agenda=agenda, event=event)
|
288 |
286 |
|
289 |
287 |
|
290 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
291 |
288 |
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
|
292 |
289 |
def test_get_pricing_context(mock_send, context, nocache):
|
293 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
294 |
|
event = Event.objects.create(
|
295 |
|
agenda=agenda, start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)), places=10
|
296 |
|
)
|
|
290 |
agenda = Agenda.objects.create(label='Foo bar')
|
297 |
291 |
pricing = Pricing.objects.create(label='Foo bar')
|
298 |
292 |
agenda_pricing = AgendaPricing.objects.create(
|
299 |
293 |
agenda=agenda,
|
... | ... | |
301 |
295 |
date_start=datetime.date(year=2021, month=9, day=1),
|
302 |
296 |
date_end=datetime.date(year=2021, month=10, day=1),
|
303 |
297 |
)
|
304 |
|
assert agenda_pricing.get_pricing_context(event, 'child:42', 'parent:35') == {}
|
|
298 |
assert (
|
|
299 |
agenda_pricing.get_pricing_context(
|
|
300 |
request=context['request'], data={}, user_external_id='child:42', adult_external_id='parent:35'
|
|
301 |
)
|
|
302 |
== {}
|
|
303 |
)
|
305 |
304 |
pricing.extra_variables = {
|
306 |
305 |
'foo': 'bar',
|
307 |
306 |
'qf': '{{ 40|add:2 }}',
|
308 |
307 |
'domicile': 'commune',
|
309 |
308 |
'ids': '{{ cards|objects:"foo"|getlist:"id"|join:"," }}',
|
310 |
|
'bad': '{% if foo %}',
|
|
309 |
'syntax_error': '{% for %}',
|
|
310 |
'variable_error': '{{ "foo"|add:user.email }}',
|
|
311 |
'event': '{{ data.event.foo }}',
|
|
312 |
'subscription': '{{ data.subscription.foo }}',
|
|
313 |
'booking': '{{ data.booking.foo }}',
|
311 |
314 |
}
|
312 |
315 |
pricing.save()
|
313 |
|
assert agenda_pricing.get_pricing_context(event, 'child:42', 'parent:35') == {
|
|
316 |
data = {
|
|
317 |
'event': {'foo': 42},
|
|
318 |
'subscription': {'foo': 43},
|
|
319 |
'booking': {'foo': 44},
|
|
320 |
}
|
|
321 |
assert agenda_pricing.get_pricing_context(
|
|
322 |
request=context['request'], data=data, user_external_id='child:42', adult_external_id='parent:35'
|
|
323 |
) == {
|
314 |
324 |
'foo': 'bar',
|
315 |
325 |
'qf': '42',
|
316 |
326 |
'domicile': 'commune',
|
317 |
327 |
'ids': '1,2',
|
|
328 |
'event': '42',
|
|
329 |
'subscription': '43',
|
|
330 |
'booking': '44',
|
318 |
331 |
}
|
319 |
332 |
|
320 |
333 |
# user_external_id and adult_external_id can be used in variables
|
... | ... | |
323 |
336 |
}
|
324 |
337 |
pricing.save()
|
325 |
338 |
mock_send.reset_mock()
|
326 |
|
agenda_pricing.get_pricing_context(event, 'child:42', 'parent:35')
|
|
339 |
agenda_pricing.get_pricing_context(
|
|
340 |
request=context['request'], data={}, user_external_id='child:42', adult_external_id='parent:35'
|
|
341 |
)
|
327 |
342 |
assert 'filter-foo=child%3A42&' in mock_send.call_args_list[0][0][0].url
|
328 |
343 |
assert 'filter-bar=parent%3A35&' in mock_send.call_args_list[0][0][0].url
|
329 |
344 |
pricing.extra_variables = {
|
... | ... | |
331 |
346 |
}
|
332 |
347 |
pricing.save()
|
333 |
348 |
mock_send.reset_mock()
|
334 |
|
agenda_pricing.get_pricing_context(event, 'child:42', 'parent:35')
|
|
349 |
agenda_pricing.get_pricing_context(
|
|
350 |
request=context['request'], data={}, user_external_id='child:42', adult_external_id='parent:35'
|
|
351 |
)
|
335 |
352 |
assert 'filter-foo=42&' in mock_send.call_args_list[0][0][0].url
|
336 |
353 |
assert 'filter-bar=35&' in mock_send.call_args_list[0][0][0].url
|
337 |
354 |
|
... | ... | |
475 |
492 |
)
|
476 |
493 |
|
477 |
494 |
|
478 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
479 |
|
def test_get_booking_modifier_event_not_checked():
|
|
495 |
def test_get_booking_modifier_unknown_check_status():
|
480 |
496 |
agenda = Agenda.objects.create(label='Foo bar')
|
481 |
|
event = Event.objects.create(
|
482 |
|
agenda=agenda, start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)), places=10
|
483 |
|
)
|
484 |
|
pricing = Pricing.objects.create(label='Foo bar')
|
485 |
|
agenda_pricing = AgendaPricing.objects.create(
|
486 |
|
agenda=agenda,
|
487 |
|
pricing=pricing,
|
488 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
489 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
490 |
|
)
|
491 |
|
with pytest.raises(PricingEventNotCheckedError):
|
492 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
493 |
|
|
494 |
|
|
495 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
496 |
|
def test_get_booking_modifier_no_subscription():
|
497 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
498 |
|
event = Event.objects.create(
|
499 |
|
agenda=agenda,
|
500 |
|
start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)),
|
501 |
|
places=10,
|
502 |
|
checked=True,
|
503 |
|
)
|
504 |
|
Subscription.objects.create(
|
505 |
|
agenda=agenda,
|
506 |
|
user_external_id='child:35', # another user
|
507 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
508 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
509 |
|
)
|
510 |
497 |
pricing = Pricing.objects.create(label='Foo bar')
|
511 |
498 |
agenda_pricing = AgendaPricing.objects.create(
|
512 |
499 |
agenda=agenda,
|
... | ... | |
514 |
501 |
date_start=datetime.date(year=2021, month=9, day=1),
|
515 |
502 |
date_end=datetime.date(year=2021, month=10, day=1),
|
516 |
503 |
)
|
517 |
|
with pytest.raises(PricingSubscriptionError):
|
518 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
519 |
|
|
520 |
|
# more than one subscription found !
|
521 |
|
Subscription.objects.create(
|
522 |
|
agenda=agenda,
|
523 |
|
user_external_id='child:42',
|
524 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
525 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
526 |
|
)
|
527 |
|
Subscription.objects.create(
|
528 |
|
agenda=agenda,
|
529 |
|
user_external_id='child:42',
|
530 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
531 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
532 |
|
)
|
533 |
|
with pytest.raises(PricingSubscriptionError):
|
534 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
|
504 |
check_status = {'status': 'unknown'}
|
|
505 |
with pytest.raises(PricingUnknownCheckStatusError):
|
|
506 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
535 |
507 |
|
536 |
508 |
|
537 |
|
@pytest.mark.parametrize(
|
538 |
|
'event_date, success',
|
539 |
|
[
|
540 |
|
# just before first day
|
541 |
|
((2021, 8, 31, 12, 00), False),
|
542 |
|
# first day
|
543 |
|
((2021, 9, 1, 12, 00), True),
|
544 |
|
# last day
|
545 |
|
((2021, 9, 30, 12, 00), True),
|
546 |
|
# just after last day
|
547 |
|
((2021, 10, 1, 12, 00), False),
|
548 |
|
],
|
549 |
|
)
|
550 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
551 |
|
def test_get_booking_modifier_subscription_date(event_date, success):
|
552 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
553 |
|
Subscription.objects.create(
|
554 |
|
agenda=agenda,
|
555 |
|
user_external_id='child:42',
|
556 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
557 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
558 |
|
)
|
559 |
|
event = Event.objects.create(
|
560 |
|
agenda=agenda, start_datetime=make_aware(datetime.datetime(*event_date)), places=10, checked=True
|
561 |
|
)
|
|
509 |
def test_get_booking_modifier_event_not_checked():
|
|
510 |
agenda = Agenda.objects.create(label='Foo bar')
|
562 |
511 |
pricing = Pricing.objects.create(label='Foo bar')
|
563 |
512 |
agenda_pricing = AgendaPricing.objects.create(
|
564 |
513 |
agenda=agenda,
|
... | ... | |
566 |
515 |
date_start=datetime.date(year=2021, month=9, day=1),
|
567 |
516 |
date_end=datetime.date(year=2021, month=10, day=1),
|
568 |
517 |
)
|
569 |
|
if success:
|
570 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
571 |
|
'status': 'not-booked',
|
572 |
|
'modifier_type': 'rate',
|
573 |
|
'modifier_rate': 0,
|
574 |
|
}
|
575 |
|
else:
|
576 |
|
with pytest.raises(PricingSubscriptionError):
|
577 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
|
518 |
check_status = {'status': 'error', 'error_reason': 'event-not-checked'}
|
|
519 |
with pytest.raises(PricingEventNotCheckedError):
|
|
520 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
578 |
521 |
|
579 |
522 |
|
580 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
581 |
523 |
def test_get_booking_modifier_no_booking():
|
582 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
583 |
|
Subscription.objects.create(
|
584 |
|
agenda=agenda,
|
585 |
|
user_external_id='child:42',
|
586 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
587 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
588 |
|
)
|
589 |
|
event = Event.objects.create(
|
590 |
|
agenda=agenda,
|
591 |
|
start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)),
|
592 |
|
places=10,
|
593 |
|
checked=True,
|
594 |
|
)
|
|
524 |
agenda = Agenda.objects.create(label='Foo bar')
|
595 |
525 |
pricing = Pricing.objects.create(label='Foo bar')
|
596 |
526 |
agenda_pricing = AgendaPricing.objects.create(
|
597 |
527 |
agenda=agenda,
|
... | ... | |
599 |
529 |
date_start=datetime.date(year=2021, month=9, day=1),
|
600 |
530 |
date_end=datetime.date(year=2021, month=10, day=1),
|
601 |
531 |
)
|
602 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
532 |
check_status = {'status': 'not-booked'}
|
|
533 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
603 |
534 |
'status': 'not-booked',
|
604 |
535 |
'modifier_type': 'rate',
|
605 |
536 |
'modifier_rate': 0,
|
606 |
537 |
}
|
607 |
538 |
|
608 |
539 |
# more than one booking found !
|
609 |
|
Booking.objects.create(event=event, user_external_id='child:42')
|
610 |
|
Booking.objects.create(event=event, user_external_id='child:42')
|
|
540 |
check_status = {'status': 'error', 'error_reason': 'too-many-bookings-found'}
|
611 |
541 |
with pytest.raises(PricingMultipleBookingError):
|
612 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
|
542 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
613 |
543 |
|
614 |
544 |
|
615 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
616 |
545 |
def test_get_booking_modifier_booking_cancelled():
|
617 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
618 |
|
Subscription.objects.create(
|
619 |
|
agenda=agenda,
|
620 |
|
user_external_id='child:42',
|
621 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
622 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
623 |
|
)
|
624 |
|
event = Event.objects.create(
|
625 |
|
agenda=agenda,
|
626 |
|
start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)),
|
627 |
|
places=10,
|
628 |
|
checked=True,
|
629 |
|
)
|
630 |
|
Booking.objects.create(event=event, user_external_id='child:42', cancellation_datetime=now())
|
|
546 |
agenda = Agenda.objects.create(label='Foo bar')
|
631 |
547 |
pricing = Pricing.objects.create(label='Foo bar')
|
632 |
548 |
agenda_pricing = AgendaPricing.objects.create(
|
633 |
549 |
agenda=agenda,
|
... | ... | |
635 |
551 |
date_start=datetime.date(year=2021, month=9, day=1),
|
636 |
552 |
date_end=datetime.date(year=2021, month=10, day=1),
|
637 |
553 |
)
|
638 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
554 |
check_status = {'status': 'cancelled'}
|
|
555 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
639 |
556 |
'status': 'cancelled',
|
640 |
557 |
'modifier_type': 'rate',
|
641 |
558 |
'modifier_rate': 0,
|
642 |
559 |
}
|
643 |
560 |
|
644 |
561 |
|
645 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
646 |
562 |
def test_get_booking_modifier_booking_not_checked():
|
647 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
648 |
|
Subscription.objects.create(
|
649 |
|
agenda=agenda,
|
650 |
|
user_external_id='child:42',
|
651 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
652 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
653 |
|
)
|
654 |
|
event = Event.objects.create(
|
655 |
|
agenda=agenda,
|
656 |
|
start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)),
|
657 |
|
places=10,
|
658 |
|
checked=True,
|
659 |
|
)
|
660 |
|
Booking.objects.create(event=event, user_external_id='child:42')
|
|
563 |
agenda = Agenda.objects.create(label='Foo bar')
|
661 |
564 |
pricing = Pricing.objects.create(label='Foo bar')
|
662 |
565 |
agenda_pricing = AgendaPricing.objects.create(
|
663 |
566 |
agenda=agenda,
|
... | ... | |
665 |
568 |
date_start=datetime.date(year=2021, month=9, day=1),
|
666 |
569 |
date_end=datetime.date(year=2021, month=10, day=1),
|
667 |
570 |
)
|
|
571 |
check_status = {'status': 'error', 'error_reason': 'booking-not-checked'}
|
668 |
572 |
with pytest.raises(PricingBookingNotCheckedError):
|
669 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
|
573 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
670 |
574 |
|
671 |
575 |
|
672 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
673 |
|
def test_get_booking_modifier_booking_absence():
|
674 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
675 |
|
Subscription.objects.create(
|
|
576 |
def test_get_booking_modifier_unknown_check_type():
|
|
577 |
agenda = Agenda.objects.create(label='Foo bar')
|
|
578 |
pricing = Pricing.objects.create(label='Foo bar')
|
|
579 |
agenda_pricing = AgendaPricing.objects.create(
|
676 |
580 |
agenda=agenda,
|
677 |
|
user_external_id='child:42',
|
|
581 |
pricing=pricing,
|
678 |
582 |
date_start=datetime.date(year=2021, month=9, day=1),
|
679 |
583 |
date_end=datetime.date(year=2021, month=10, day=1),
|
680 |
584 |
)
|
681 |
|
event = Event.objects.create(
|
682 |
|
agenda=agenda,
|
683 |
|
start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)),
|
684 |
|
places=10,
|
685 |
|
checked=True,
|
686 |
|
)
|
687 |
|
booking = Booking.objects.create(event=event, user_external_id='child:42', user_was_present=False)
|
|
585 |
check_status = {'status': 'presence', 'check_type': 'unknown'}
|
|
586 |
with pytest.raises(PricingBookingCheckTypeError) as e:
|
|
587 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
|
588 |
assert e.value.details == {
|
|
589 |
'reason': 'not-found',
|
|
590 |
}
|
|
591 |
check_status = {'status': 'absence', 'check_type': 'unknown'}
|
|
592 |
with pytest.raises(PricingBookingCheckTypeError) as e:
|
|
593 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
|
594 |
assert e.value.details == {
|
|
595 |
'reason': 'not-found',
|
|
596 |
}
|
|
597 |
|
|
598 |
|
|
599 |
def test_get_booking_modifier_booking_absence():
|
|
600 |
agenda = Agenda.objects.create(label='Foo bar')
|
688 |
601 |
pricing = Pricing.objects.create(label='Foo bar')
|
689 |
602 |
agenda_pricing = AgendaPricing.objects.create(
|
690 |
603 |
agenda=agenda,
|
... | ... | |
694 |
607 |
)
|
695 |
608 |
|
696 |
609 |
# no check type
|
697 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
610 |
check_status = {'status': 'absence', 'check_type': ''}
|
|
611 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
698 |
612 |
'status': 'absence',
|
699 |
613 |
'check_type_group': None,
|
700 |
614 |
'check_type': None,
|
... | ... | |
702 |
616 |
'modifier_rate': 0,
|
703 |
617 |
}
|
704 |
618 |
|
705 |
|
# check_type but incomplete configuration
|
|
619 |
# check_type but not configured on agenda
|
706 |
620 |
group = CheckTypeGroup.objects.create(label='Foo bar')
|
707 |
621 |
check_type = CheckType.objects.create(label='Foo reason', group=group, kind='absence')
|
708 |
|
booking.user_check_type = check_type
|
709 |
|
booking.save()
|
|
622 |
check_status = {'status': 'absence', 'check_type': check_type.slug}
|
710 |
623 |
with pytest.raises(PricingBookingCheckTypeError) as e:
|
711 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
|
624 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
|
625 |
assert e.value.details == {
|
|
626 |
'reason': 'not-found',
|
|
627 |
}
|
|
628 |
# incomplete configuration
|
|
629 |
agenda.check_type_group = group
|
|
630 |
agenda.save()
|
|
631 |
with pytest.raises(PricingBookingCheckTypeError) as e:
|
|
632 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
712 |
633 |
assert e.value.details == {
|
713 |
634 |
'check_type_group': 'foo-bar',
|
714 |
635 |
'check_type': 'foo-reason',
|
... | ... | |
717 |
638 |
|
718 |
639 |
check_type.pricing = 42
|
719 |
640 |
check_type.save()
|
720 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
641 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
721 |
642 |
'status': 'absence',
|
722 |
643 |
'check_type_group': 'foo-bar',
|
723 |
644 |
'check_type': 'foo-reason',
|
... | ... | |
727 |
648 |
|
728 |
649 |
check_type.pricing = 0
|
729 |
650 |
check_type.save()
|
730 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
651 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
731 |
652 |
'status': 'absence',
|
732 |
653 |
'check_type_group': 'foo-bar',
|
733 |
654 |
'check_type': 'foo-reason',
|
... | ... | |
738 |
659 |
check_type.pricing = None
|
739 |
660 |
check_type.pricing_rate = 20
|
740 |
661 |
check_type.save()
|
741 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
662 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
742 |
663 |
'status': 'absence',
|
743 |
664 |
'check_type_group': 'foo-bar',
|
744 |
665 |
'check_type': 'foo-reason',
|
... | ... | |
748 |
669 |
|
749 |
670 |
check_type.pricing_rate = 0
|
750 |
671 |
check_type.save()
|
751 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
672 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
752 |
673 |
'status': 'absence',
|
753 |
674 |
'check_type_group': 'foo-bar',
|
754 |
675 |
'check_type': 'foo-reason',
|
... | ... | |
760 |
681 |
check_type.kind = 'presence'
|
761 |
682 |
check_type.save()
|
762 |
683 |
with pytest.raises(PricingBookingCheckTypeError) as e:
|
763 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
|
684 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
764 |
685 |
assert e.value.details == {
|
765 |
686 |
'check_type_group': 'foo-bar',
|
766 |
687 |
'check_type': 'foo-reason',
|
... | ... | |
768 |
689 |
}
|
769 |
690 |
|
770 |
691 |
|
771 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
772 |
692 |
def test_get_booking_modifier_booking_presence():
|
773 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
774 |
|
Subscription.objects.create(
|
775 |
|
agenda=agenda,
|
776 |
|
user_external_id='child:42',
|
777 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
778 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
779 |
|
)
|
780 |
|
event = Event.objects.create(
|
781 |
|
agenda=agenda,
|
782 |
|
start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)),
|
783 |
|
places=10,
|
784 |
|
checked=True,
|
785 |
|
)
|
786 |
|
booking = Booking.objects.create(event=event, user_external_id='child:42', user_was_present=True)
|
|
693 |
agenda = Agenda.objects.create(label='Foo bar')
|
787 |
694 |
pricing = Pricing.objects.create(label='Foo bar')
|
788 |
695 |
agenda_pricing = AgendaPricing.objects.create(
|
789 |
696 |
agenda=agenda,
|
... | ... | |
793 |
700 |
)
|
794 |
701 |
|
795 |
702 |
# no check type
|
796 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
703 |
check_status = {'status': 'presence', 'check_type': ''}
|
|
704 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
797 |
705 |
'status': 'presence',
|
798 |
706 |
'check_type_group': None,
|
799 |
707 |
'check_type': None,
|
... | ... | |
801 |
709 |
'modifier_rate': 100,
|
802 |
710 |
}
|
803 |
711 |
|
804 |
|
# check_type but incomplete configuration
|
|
712 |
# check_type but not configured on agenda
|
805 |
713 |
group = CheckTypeGroup.objects.create(label='Foo bar')
|
806 |
714 |
check_type = CheckType.objects.create(label='Foo reason', group=group, kind='presence')
|
807 |
|
booking.user_check_type = check_type
|
808 |
|
booking.save()
|
|
715 |
check_status = {'status': 'presence', 'check_type': check_type.slug}
|
|
716 |
with pytest.raises(PricingBookingCheckTypeError) as e:
|
|
717 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
|
718 |
assert e.value.details == {
|
|
719 |
'reason': 'not-found',
|
|
720 |
}
|
|
721 |
# incomplete configuration
|
|
722 |
agenda.check_type_group = group
|
|
723 |
agenda.save()
|
809 |
724 |
with pytest.raises(PricingBookingCheckTypeError) as e:
|
810 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
|
725 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
811 |
726 |
assert e.value.details == {
|
812 |
727 |
'check_type_group': 'foo-bar',
|
813 |
728 |
'check_type': 'foo-reason',
|
... | ... | |
816 |
731 |
|
817 |
732 |
check_type.pricing = 42
|
818 |
733 |
check_type.save()
|
819 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
734 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
820 |
735 |
'status': 'presence',
|
821 |
736 |
'check_type_group': 'foo-bar',
|
822 |
737 |
'check_type': 'foo-reason',
|
... | ... | |
826 |
741 |
|
827 |
742 |
check_type.pricing = 0
|
828 |
743 |
check_type.save()
|
829 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
744 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
830 |
745 |
'status': 'presence',
|
831 |
746 |
'check_type_group': 'foo-bar',
|
832 |
747 |
'check_type': 'foo-reason',
|
... | ... | |
837 |
752 |
check_type.pricing = None
|
838 |
753 |
check_type.pricing_rate = 150
|
839 |
754 |
check_type.save()
|
840 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
755 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
841 |
756 |
'status': 'presence',
|
842 |
757 |
'check_type_group': 'foo-bar',
|
843 |
758 |
'check_type': 'foo-reason',
|
... | ... | |
847 |
762 |
|
848 |
763 |
check_type.pricing_rate = 0
|
849 |
764 |
check_type.save()
|
850 |
|
assert agenda_pricing.get_booking_modifier(event, 'child:42') == {
|
|
765 |
assert agenda_pricing.get_booking_modifier(check_status=check_status) == {
|
851 |
766 |
'status': 'presence',
|
852 |
767 |
'check_type_group': 'foo-bar',
|
853 |
768 |
'check_type': 'foo-reason',
|
... | ... | |
859 |
774 |
check_type.kind = 'absence'
|
860 |
775 |
check_type.save()
|
861 |
776 |
with pytest.raises(PricingBookingCheckTypeError) as e:
|
862 |
|
agenda_pricing.get_booking_modifier(event, 'child:42')
|
|
777 |
agenda_pricing.get_booking_modifier(check_status=check_status)
|
863 |
778 |
assert e.value.details == {
|
864 |
779 |
'check_type_group': 'foo-bar',
|
865 |
780 |
'check_type': 'foo-reason',
|
... | ... | |
867 |
782 |
}
|
868 |
783 |
|
869 |
784 |
|
870 |
|
@pytest.mark.xfail(reason='no link to events yet')
|
871 |
785 |
def test_get_pricing_data(context):
|
872 |
|
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
873 |
|
event = Event.objects.create(
|
874 |
|
agenda=agenda,
|
875 |
|
start_datetime=make_aware(datetime.datetime(2021, 9, 15, 12, 00)),
|
876 |
|
places=10,
|
877 |
|
checked=True,
|
878 |
|
)
|
879 |
|
Subscription.objects.create(
|
880 |
|
agenda=agenda,
|
881 |
|
user_external_id='child:42',
|
882 |
|
date_start=datetime.date(year=2021, month=9, day=1),
|
883 |
|
date_end=datetime.date(year=2021, month=10, day=1),
|
884 |
|
)
|
|
786 |
agenda = Agenda.objects.create(label='Foo bar')
|
885 |
787 |
category = CriteriaCategory.objects.create(label='Foo', slug='foo')
|
886 |
788 |
criteria = Criteria.objects.create(label='Bar', slug='bar', condition='True', category=category)
|
887 |
789 |
pricing = Pricing.objects.create(
|
... | ... | |
902 |
804 |
'foo:bar': 42,
|
903 |
805 |
},
|
904 |
806 |
)
|
905 |
|
assert AgendaPricing.get_pricing_data(context['request'], event, 'child:42', 'parent:35') == {
|
|
807 |
assert AgendaPricing.get_pricing_data(
|
|
808 |
request=context['request'],
|
|
809 |
agenda=agenda,
|
|
810 |
event={'start_datetime': make_aware(datetime.datetime(2021, 9, 15, 12, 00)).isoformat()},
|
|
811 |
subscription={},
|
|
812 |
check_status={'status': 'not-booked'},
|
|
813 |
booking={},
|
|
814 |
user_external_id='child:42',
|
|
815 |
adult_external_id='parent:35',
|
|
816 |
) == {
|
906 |
817 |
'pricing': 0,
|
907 |
818 |
'calculation_details': {
|
908 |
819 |
'pricing': 42,
|