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_max_200_and_actual_110(self): # Given physical_cap_booking = create_booking_for_thing(amount=50, product_type=ThingType.CINEMA_ABO) digital_cap_booking = create_booking_for_thing(url='http://test.com', amount=110, product_type=ThingType.MUSIQUE) bookings = [physical_cap_booking, digital_cap_booking] # When expenses = get_expenses(bookings) # Then assert expenses['digital'] == {'max': 200, 'actual': 110}
def test_max_200_and_actual_50(self): # Given physical_cap_booking = create_booking_for_thing(amount=50, product_type=ThingType.AUDIOVISUEL) digital_cap_booking = create_booking_for_thing(url='http://test.com', amount=60, product_type=ThingType.AUDIOVISUEL) bookings = [physical_cap_booking, digital_cap_booking] # When expenses = get_expenses(bookings) # Then assert expenses['physical'] == {'max': 200, 'actual': 50}
def test_returns_max_200_and_actual_0(self): # Given booking_1 = create_booking_for_thing(amount=50) bookings = [booking_1] # When expenses = get_expenses(bookings) # Then assert expenses['digital'] == {'max': 200, 'actual': 0}
def test_max_200_and_actual_0(self): # Given booking_1 = create_booking_for_thing(url='http://test.com', amount=60) bookings = [booking_1] # When expenses = get_expenses(bookings) # Then assert expenses['physical'] == {'max': 200, 'actual': 0}
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_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_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_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_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_100000_EUROS.value.apply( booking) # then assert reimbursed_amount == Decimal(0.65) * 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.MAX_REIMBURSEMENT.value.apply( booking) # then assert reimbursed_amount == 0
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)
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.value
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_offline_offer_is_a_physical_expense(self): # Given bookings = [ create_booking_for_thing(amount=50, url=None, product_type=ThingType.MUSIQUE) ] # When expenses = get_expenses(bookings) # Then assert expenses['digital']['actual'] == 0 assert expenses['physical']['actual'] == 50
def test_online_offer_is_a_physical_expense(self): # Given bookings = [ create_booking_for_thing(amount=50, url='http://on.line', product_type=ThingType.LIVRE_EDITION) ] # When expenses = get_expenses(bookings) # Then assert expenses['physical']['actual'] == 50 assert expenses['digital']['actual'] == 0
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_offline_offer_is_not_capped(self): # Given bookings = [ create_booking_for_thing(amount=50, url=None, product_type=ThingType.JEUX_VIDEO_ABO) ] # When expenses = get_expenses(bookings) # Then assert expenses['digital']['actual'] == 0 assert expenses['physical']['actual'] == 0
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_physical_things_with_cumulative_value_above_100000( self): # given rule = ReimbursementRules.ABOVE_100000_EUROS.value booking = create_booking_for_thing(url=None, amount=40, quantity=3) cumulative_booking_value = 100100 # when is_relevant = rule.is_relevant( booking, cumulative_value=cumulative_booking_value) # then assert is_relevant is True
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_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_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_check_expenses_limits_raises_an_error_when_digital_limit_is_reached(self): # given expenses = { 'physical': {'max': SUBVENTION_PHYSICAL_THINGS, 'actual': 10}, 'digital': {'max': SUBVENTION_DIGITAL_THINGS, 'actual': 190} } booking = Booking(from_dict={'stockId': humanize(123), 'amount': 11, 'quantity': 1}) stock = create_booking_for_thing(url='http://on.line', product_type=ThingType.JEUX_VIDEO).stock mocked_query = Mock(return_value=stock) # when with pytest.raises(ApiErrors) as api_errors: check_expenses_limits(expenses, booking, find_stock=mocked_query) # then assert api_errors.value.errors['global'] == ['Le plafond de %s € pour les offres numériques ne vous permet pas ' \ 'de réserver cette offre.' % SUBVENTION_DIGITAL_THINGS]
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