def test_returns_max_500_and_actual_210(self): # Given booking_1 = create_booking_for_thing(amount=90) booking_2 = create_booking_for_event(amount=60, quantity=2) booking_3 = create_booking_for_event(amount=20, isCancelled=True) bookings = [booking_1, booking_2, booking_3] # When expenses = get_expenses(bookings) # Then assert expenses['all'] == {'max': 500, 'actual': 210}
def test_returns_full_reimbursement_for_all_bookings(self): # given booking1 = create_booking_for_event(amount=50, quantity=1) booking2 = create_booking_for_thing(amount=40, quantity=3) booking3 = create_booking_for_event(amount=100, quantity=2) bookings = [booking1, booking2, booking3] # when booking_reimbursements = find_all_booking_reimbursements( bookings, NEW_RULES) # then assert_total_reimbursement(booking_reimbursements[0], booking1) assert_total_reimbursement(booking_reimbursements[1], booking2) assert_total_reimbursement(booking_reimbursements[2], booking3)
def test_returns_85_reimbursement_rate_between_40000_and_100000_when_cumulative_value_is_100000( self): # given booking1 = create_booking_for_event(amount=19000, quantity=1) booking2 = create_booking_for_thing(url='http://truc', amount=50, quantity=3) booking3 = create_booking_for_thing(amount=19000, quantity=4) booking4 = create_booking_for_thing(amount=5000, quantity=1) bookings = [booking1, booking2, booking3, booking4] cumulative_value_for_bookings_1_and_3_and_4 = booking1.amount * booking1.quantity + \ booking3.amount * booking3.quantity + \ booking4.amount * booking4.quantity # when booking_reimbursements = find_all_booking_reimbursements( bookings, NEW_RULES) # then assert_total_reimbursement(booking_reimbursements[0], booking1) assert_no_reimbursement_for_digital(booking_reimbursements[1], booking2) assert_degressive_reimbursement( booking_reimbursements[2], booking3, cumulative_value_for_bookings_1_and_3_and_4) assert_degressive_reimbursement( booking_reimbursements[3], booking4, cumulative_value_for_bookings_1_and_3_and_4)
def test_returns_full_reimbursement_for_all_bookings_above_20000_if_rule_is_not_valid_anymore( self): # given now = datetime.utcnow() booking1 = create_booking_for_event(amount=50, quantity=1, date_created=now) booking2 = create_booking_for_thing(url='http://truc', amount=50, quantity=3, date_created=now) booking3 = create_booking_for_thing(amount=1995, quantity=10, date_created=now) bookings = [booking1, booking2, booking3] ReimbursementRules.MAX_REIMBURSEMENT.value.valid_from = now - timedelta( weeks=5) ReimbursementRules.MAX_REIMBURSEMENT.value.valid_until = now + timedelta( weeks=5) # when booking_reimbursements = find_all_booking_reimbursements( bookings, CURRENT_RULES) # then assert_total_reimbursement(booking_reimbursements[0], booking1) assert_no_reimbursement_for_digital(booking_reimbursements[1], booking2) assert_total_reimbursement(booking_reimbursements[2], booking3) # tear down ReimbursementRules.MAX_REIMBURSEMENT.value.valid_from = None ReimbursementRules.MAX_REIMBURSEMENT.value.valid_until = None
def test_returns_a_different_reimbursement_for_digital_booking(self): # given booking1 = create_booking_for_event(amount=50, quantity=1) booking2 = create_booking_for_thing(url='http://truc', amount=40, quantity=3) booking3 = create_booking_for_event(amount=100, quantity=2) bookings = [booking1, booking2, booking3] # when booking_reimbursements = find_all_booking_reimbursements( bookings, NEW_RULES) # then assert_total_reimbursement(booking_reimbursements[2], booking3) assert_total_reimbursement(booking_reimbursements[0], booking1) assert_no_reimbursement_for_digital(booking_reimbursements[1], booking2)
def test_is_relevant_for_booking_on_events(self): # given booking = create_booking_for_event(amount=50, quantity=1) # when is_relevant = ReimbursementRules.PHYSICAL_OFFERS.value.is_relevant( booking) # then assert is_relevant is True
def test_is_not_relevant_for_booking_on_events(self): # given booking = create_booking_for_event(amount=50, quantity=1) # when is_relevant = ReimbursementRules.DIGITAL_THINGS.value.is_relevant( booking) # then assert is_relevant is False
def test_offline_offer_is_not_capped(self): # Given bookings = [ create_booking_for_event(amount=50, type=EventType.SPECTACLE_VIVANT) ] # When expenses = get_expenses(bookings) # Then assert expenses['digital']['actual'] == 0 assert expenses['physical']['actual'] == 0
def test_offline_offer_is_not_capped(self): # Given bookings = [ create_booking_for_event(amount=50, type=EventType.CONFERENCE_DEBAT_DEDICACE) ] # When expenses = get_expenses(bookings) # Then assert expenses['digital']['actual'] == 0 assert expenses['physical']['actual'] == 0
def test_is_not_relevant_for_booking_on_events_with_cumulative_value_below_20000( self): # given rule = ReimbursementRules.MAX_REIMBURSEMENT.value booking = create_booking_for_event(amount=30, quantity=3) cumulative_booking_value = 19000 # when is_relevant = rule.is_relevant( booking, cumulative_value=cumulative_booking_value) # then assert is_relevant is False
def test_is_not_relevant_for_booking_on_events_with_cumulative_value_of_exactly_100000( self): # given rule = ReimbursementRules.ABOVE_100000_EUROS.value booking = create_booking_for_event(amount=40, quantity=3) cumulative_booking_value = 100000 # when is_relevant = rule.is_relevant( booking, cumulative_value=cumulative_booking_value) # then assert is_relevant is False
def test_is_relevant_for_booking_on_events_with_cumulative_value_above_20000( self): # given rule = ReimbursementRules.BETWEEN_20000_AND_40000_EUROS.value booking = create_booking_for_event(amount=40, quantity=3) cumulative_booking_value = 20100 # when is_relevant = rule.is_relevant( booking, cumulative_value=cumulative_booking_value) # then assert is_relevant is True
def test_returns_65_reimbursement_rate_above_100000_euros_for_last_booking( self): # given booking1 = create_booking_for_event(amount=19000, quantity=1) booking2 = create_booking_for_thing(url='http://truc', amount=50, quantity=3) booking3 = create_booking_for_thing(amount=2000, quantity=120) bookings = [booking1, booking2, booking3] # when booking_reimbursements = find_all_booking_reimbursements( bookings, NEW_RULES) # then assert_total_reimbursement(booking_reimbursements[0], booking1) assert_degressive_reimbursement(booking_reimbursements[2], booking3, 430000) assert_no_reimbursement_for_digital(booking_reimbursements[1], booking2)
def test_returns_no_reimbursement_above_20000_euros_for_last_booking( self): # given booking1 = create_booking_for_event(amount=60, quantity=1) booking2 = create_booking_for_thing(url='http://truc', amount=50, quantity=3) booking3 = create_booking_for_thing(amount=1995, quantity=10) bookings = [booking1, booking2, booking3] # when booking_reimbursements = find_all_booking_reimbursements( bookings, CURRENT_RULES) # then assert_total_reimbursement(booking_reimbursements[0], booking1) assert_no_reimbursement_for_digital(booking_reimbursements[1], booking2) assert_no_reimbursement_beyond_max(booking_reimbursements[2], booking3)
def test_returns_full_reimbursement_when_cumulative_value_is_20000( self): # given booking1 = create_booking_for_event(amount=19990, quantity=1) booking2 = create_booking_for_thing(url='http://truc', amount=50, quantity=3) booking3 = create_booking_for_thing(amount=10, quantity=1) bookings = [booking1, booking2, booking3] cumulative_value_for_bookings_1_and_3 = booking1.amount * booking1.quantity + \ booking3.amount * booking3.quantity # when booking_reimbursements = find_all_booking_reimbursements( bookings, NEW_RULES) # then assert_total_reimbursement(booking_reimbursements[0], booking1) assert_total_reimbursement(booking_reimbursements[2], booking3) assert_no_reimbursement_for_digital(booking_reimbursements[1], booking2)