示例#1
0
            def test_returns_max_500_and_actual_0(self):
                # Given
                bookings = []

                # When
                expenses = get_expenses(bookings)

                # Then
                assert expenses['all'] == {'max': 500, 'actual': 0}
示例#2
0
            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}
示例#3
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}
示例#4
0
            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
示例#5
0
            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
示例#6
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}
示例#7
0
            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
示例#8
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
示例#9
0
            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
示例#10
0
def create_booking():
    stock_id = request.json.get('stockId')
    recommendation_id = request.json.get('recommendationId')
    quantity = request.json.get('quantity')

    stock = Stock.query.filter_by(id=dehumanize(stock_id)).first()

    try:
        check_has_stock_id(stock_id)
        check_existing_stock(stock)
        user_bookings = find_all_bookings_for_stock_and_user(
            stock, current_user)
        check_already_booked(user_bookings)
        check_has_quantity(quantity)
        check_booking_quantity_limit(quantity)
        check_offer_date(stock)
        check_not_soft_deleted_stock(stock)
        check_can_book_free_offer(stock, current_user)
        check_offer_is_active(stock)
        check_stock_booking_limit_date(stock)
        check_stock_venue_is_validated(stock)
    except ApiErrors as api_errors:
        return jsonify(api_errors.errors), 400

    new_booking = Booking(
        from_dict={
            'stockId': stock_id,
            'amount': stock.price,
            'token': random_token(),
            'userId': humanize(current_user.id),
            'quantity': quantity,
            'recommendationId':
            recommendation_id if recommendation_id else None
        })

    bookings = find_active_bookings_by_user_id(current_user.id)

    expenses = get_expenses(bookings)
    check_expenses_limits(expenses, new_booking)
    PcObject.save(new_booking)

    try:
        send_booking_recap_emails(new_booking, send_raw_email)
    except MailServiceException as e:
        app.logger.error('Mail service failure', e)
    try:
        send_booking_confirmation_email_to_user(new_booking, send_raw_email)
    except MailServiceException as e:
        app.logger.error('Mail service failure', e)

    return jsonify(
        as_dict(new_booking, includes=WEBAPP_PATCH_POST_BOOKING_INCLUDES)), 201
示例#11
0
            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}
示例#12
0
            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}
示例#13
0
 def expenses(self):
     return get_expenses(self.userBookings)