def test_returns_85_reimbursement_rate_between_40000_and_150000_when_cumulative_value_is_150000( 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_85_reimbursement_rate_between_20000_and_40000_euros_for_this_civil_year( self): # given booking1 = create_booking_for_event(amount=20000, quantity=1, date_created=datetime( 2018, 1, 1)) booking2 = create_booking_for_thing(amount=25000, quantity=1, date_created=datetime( 2019, 1, 1)) booking3 = create_booking_for_thing(amount=2000, quantity=1, date_created=datetime( 2019, 1, 1)) 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[1], booking2, 25000) assert_degressive_reimbursement(booking_reimbursements[2], booking3, 27000)
def test_returns_full_reimbursement_for_all_bookings_for_new_civil_year( self): # given booking1 = create_booking_for_event(amount=10000, quantity=1, date_created=datetime( 2018, 1, 1)) booking2 = create_booking_for_thing(amount=10000, quantity=1, date_created=datetime( 2018, 1, 1)) booking3 = create_booking_for_event(amount=200, quantity=2, date_created=datetime( 2019, 1, 1)) 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_is_relevant_for_booking_on_physical_things(self): # given booking = create_booking_for_thing(url=None, amount=40, quantity=3) # when is_relevant = ReimbursementRules.PHYSICAL_OFFERS.value.is_relevant( booking) # then assert is_relevant is True
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] # 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)
def test_is_not_relevant_for_booking_on_physical_things(self): # given booking = create_booking_for_thing(url=None, amount=40, quantity=3) # when is_relevant = ReimbursementRules.DIGITAL_THINGS.value.is_relevant( booking) # then assert is_relevant is False
def test_returns_65_reimbursement_rate_above_150000_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_relevant_for_booking_on_digital_things(self): # given booking = create_booking_for_thing(url="http://", amount=40, quantity=3) # when is_relevant = ReimbursementRules.DIGITAL_THINGS.value.is_relevant( booking) # then assert is_relevant is True
def test_is_not_relevant_for_booking_on_digital_things(self): # given booking = create_booking_for_thing(url="http://", amount=40, quantity=3) # when is_relevant = ReimbursementRules.PHYSICAL_OFFERS.value.is_relevant( booking) # then assert is_relevant is False
def test_apply_for_booking_returns_a_reimbursed_amount(self): # given booking = create_booking_for_thing(url="http://", amount=40, quantity=3) # when reimbursed_amount = ReimbursementRules.MAX_REIMBURSEMENT.value.apply( booking) # then assert reimbursed_amount == 0
def test_apply_for_booking_returns_a_reimbursed_amount(self): # given booking = create_booking_for_thing(url="http://", amount=40, quantity=3) # when reimbursed_amount = ReimbursementRules.ABOVE_150000_EUROS.value.apply( booking) # then assert reimbursed_amount == Decimal(0.7) * 40 * 3
def test_apply_for_booking_returns_a_reimbursed_amount(self): # given booking = create_booking_for_thing(url="http://", amount=40, quantity=3) # when reimbursed_amount = ReimbursementRules.PHYSICAL_OFFERS.value.apply( booking) # then assert reimbursed_amount == booking.total_amount
def test_is_relevant_for_booking_on_physical_things_with_cumulative_value_above_150000( self): # given rule = ReimbursementRules.ABOVE_150000_EUROS.value booking = create_booking_for_thing(url=None, amount=40, quantity=3) cumulative_booking_value = 150100 # when is_relevant = rule.is_relevant( booking, cumulative_value=cumulative_booking_value) # then assert is_relevant is True
def test_is_relevant_for_booking_on_cinema_cards(self): # given booking = create_booking_for_thing(url="http://cinema.card", amount=40, quantity=2, product_type=ThingType.CINEMA_CARD) # when is_relevant = ReimbursementRules.PHYSICAL_OFFERS.value.is_relevant( booking) # then assert is_relevant is True
def test_is_not_relevant_for_cinema_cards(self): # given booking = create_booking_for_thing(url="http://cinema.card", amount=40, quantity=3, product_type=ThingType.CINEMA_CARD) # when is_relevant = ReimbursementRules.DIGITAL_THINGS.value.is_relevant( booking) # then assert is_relevant is False
def test_is_not_relevant_for_booking_on_physical_things_with_cumulative_value_of_exactly_20000( self): # given rule = ReimbursementRules.BETWEEN_20000_AND_40000_EUROS.value booking = create_booking_for_thing(url=None, amount=40, quantity=3) cumulative_booking_value = 20000 # 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_physical_things_with_cumulative_value_below_20000( self): # given rule = ReimbursementRules.MAX_REIMBURSEMENT.value booking = create_booking_for_thing(url=None, 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_relevant_for_booking_on_digital_books(self): # given booking = create_booking_for_thing( url="http://my.book", amount=40, quantity=3, product_type=ThingType.LIVRE_EDITION) # when is_relevant = ReimbursementRules.PHYSICAL_OFFERS.value.is_relevant( booking) # then assert is_relevant is True
def test_apply_for_booking_returns_a_reimbursed_amount(self): # given booking = create_booking_for_thing( product_type=ThingType.LIVRE_EDITION, url=None, amount=40, quantity=3) # when reimbursed_amount = ReimbursementRules.BOOK_REIMBURSEMENT.value.apply( booking) # then assert reimbursed_amount == Decimal(0.95) * 40 * 3
def test_is_not_relevant_for_digital_books(self): # given booking = create_booking_for_thing( url="http://my.book", amount=40, quantity=3, product_type=ThingType.LIVRE_EDITION) # when is_relevant = ReimbursementRules.DIGITAL_THINGS.value.is_relevant( booking) # then assert is_relevant is False
def test_returns_95_reimbursement_rate_between_20000_and_40000_euros_for_most_recent_booking( 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=20, 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_degressive_reimbursement( booking_reimbursements[2], booking3, cumulative_value_for_bookings_1_and_3) assert_no_reimbursement_for_digital(booking_reimbursements[1], booking2)
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_is_not_relevant_for_booking_on_digital_things_with_cumulative_value_above_20000( self): # given rule = ReimbursementRules.MAX_REIMBURSEMENT.value booking = create_booking_for_thing(url="http://truc", 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 False
def test_is_relevant_for_booking_on_book_with_cumulative_value_above_20000( self): # given rule = ReimbursementRules.BOOK_REIMBURSEMENT.value booking = create_booking_for_thing( product_type=ThingType.LIVRE_EDITION, url=None, amount=40, quantity=3) cumulative_booking_value = 55000 # when is_relevant = rule.is_relevant( booking, cumulative_value=cumulative_booking_value) # then assert is_relevant is True
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)