pricing: adapt get_agenda_pricing method for flat fee schedule mode (#67675)
This commit is contained in:
parent
83684c3899
commit
f0503f9190
|
@ -462,11 +462,12 @@ class AgendaPricing(models.Model):
|
|||
}
|
||||
|
||||
@staticmethod
|
||||
def get_agenda_pricing(agenda, start_date):
|
||||
def get_agenda_pricing(agenda, start_date, flat_fee_schedule):
|
||||
try:
|
||||
return agenda.agendapricings.get(
|
||||
date_start__lte=start_date,
|
||||
date_end__gt=start_date,
|
||||
flat_fee_schedule=flat_fee_schedule,
|
||||
)
|
||||
except (AgendaPricing.DoesNotExist, AgendaPricing.MultipleObjectsReturned):
|
||||
raise AgendaPricingNotFound
|
||||
|
|
|
@ -287,30 +287,80 @@ def test_get_agenda_pricing():
|
|||
|
||||
# not found
|
||||
with pytest.raises(AgendaPricingNotFound):
|
||||
AgendaPricing.get_agenda_pricing(agenda=agenda, start_date=start_date)
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=False,
|
||||
)
|
||||
with pytest.raises(AgendaPricingNotFound):
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=True,
|
||||
)
|
||||
|
||||
# ok
|
||||
agenda_pricing = AgendaPricing.objects.create(
|
||||
pricing=pricing,
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
flat_fee_schedule=False,
|
||||
)
|
||||
agenda_pricing.agendas.add(agenda)
|
||||
assert AgendaPricing.get_agenda_pricing(agenda=agenda, start_date=start_date) == agenda_pricing
|
||||
agenda_pricing2 = AgendaPricing.objects.create(
|
||||
pricing=pricing,
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
flat_fee_schedule=True,
|
||||
)
|
||||
agenda_pricing2.agendas.add(agenda)
|
||||
assert (
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=False,
|
||||
)
|
||||
== agenda_pricing
|
||||
)
|
||||
assert (
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=True,
|
||||
)
|
||||
== agenda_pricing2
|
||||
)
|
||||
|
||||
# more than one matching
|
||||
agenda_pricing = AgendaPricing.objects.create(
|
||||
pricing=pricing,
|
||||
date_start=datetime.date(year=2021, month=9, day=14),
|
||||
date_end=datetime.date(year=2021, month=9, day=16),
|
||||
flat_fee_schedule=False,
|
||||
)
|
||||
agenda_pricing.agendas.add(agenda)
|
||||
agenda_pricing2 = AgendaPricing.objects.create(
|
||||
pricing=pricing,
|
||||
date_start=datetime.date(year=2021, month=9, day=14),
|
||||
date_end=datetime.date(year=2021, month=9, day=16),
|
||||
flat_fee_schedule=True,
|
||||
)
|
||||
agenda_pricing2.agendas.add(agenda)
|
||||
with pytest.raises(AgendaPricingNotFound):
|
||||
AgendaPricing.get_agenda_pricing(agenda=agenda, start_date=start_date)
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=False,
|
||||
)
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=True,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'event_date, found',
|
||||
'start_date, found',
|
||||
[
|
||||
# just before first day
|
||||
((2021, 8, 31), False),
|
||||
|
@ -322,21 +372,53 @@ def test_get_agenda_pricing():
|
|||
((2021, 10, 1), False),
|
||||
],
|
||||
)
|
||||
def test_get_agenda_pricing_event_date(event_date, found):
|
||||
def test_get_agenda_pricing_start_date(start_date, found):
|
||||
agenda = Agenda.objects.create(label='Foo bar')
|
||||
pricing = Pricing.objects.create(label='Foo bar')
|
||||
agenda_pricing = AgendaPricing.objects.create(
|
||||
pricing=pricing,
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
flat_fee_schedule=False,
|
||||
)
|
||||
agenda_pricing.agendas.add(agenda)
|
||||
start_date = datetime.date(*event_date)
|
||||
agenda_pricing2 = AgendaPricing.objects.create(
|
||||
pricing=pricing,
|
||||
date_start=datetime.date(year=2021, month=9, day=1),
|
||||
date_end=datetime.date(year=2021, month=10, day=1),
|
||||
flat_fee_schedule=True,
|
||||
)
|
||||
agenda_pricing2.agendas.add(agenda)
|
||||
start_date = datetime.date(*start_date)
|
||||
if found:
|
||||
assert AgendaPricing.get_agenda_pricing(agenda=agenda, start_date=start_date) == agenda_pricing
|
||||
assert (
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=False,
|
||||
)
|
||||
== agenda_pricing
|
||||
)
|
||||
assert (
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=True,
|
||||
)
|
||||
== agenda_pricing2
|
||||
)
|
||||
else:
|
||||
with pytest.raises(AgendaPricingNotFound):
|
||||
AgendaPricing.get_agenda_pricing(agenda=agenda, start_date=start_date)
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=False,
|
||||
)
|
||||
AgendaPricing.get_agenda_pricing(
|
||||
agenda=agenda,
|
||||
start_date=start_date,
|
||||
flat_fee_schedule=True,
|
||||
)
|
||||
|
||||
|
||||
@mock.patch('requests.Session.send', side_effect=mocked_requests_send)
|
||||
|
|
Loading…
Reference in New Issue