コード例 #1
0
    def test_no_op_when_educational_booking_already_refused(self, db_session):
        stock = offers_factories.EducationalEventStockFactory(
            dnBookedQuantity=20)
        booking = bookings_factories.EducationalBookingFactory(
            educationalBooking__status=EducationalBookingStatus.REFUSED,
            quantity=1,
            stock=stock,
        )

        educational_api.refuse_educational_booking(
            booking.educationalBookingId)

        assert stock.dnBookedQuantity == 21
コード例 #2
0
    def test_refuse_educational_booking(self, db_session):
        stock = offers_factories.EducationalEventStockFactory(
            quantity=200, dnBookedQuantity=0)
        booking = bookings_factories.EducationalBookingFactory(
            status=BookingStatus.CONFIRMED,
            stock=stock,
            quantity=20,
        )

        educational_api.refuse_educational_booking(
            booking.educationalBookingId)

        assert stock.dnBookedQuantity == 0
        assert booking.status == BookingStatus.CANCELLED
        assert booking.cancellationReason == BookingCancellationReasons.REFUSED_BY_INSTITUTE
コード例 #3
0
    def test_refuse_educational_booking_stock_lock(self, app):
        booking = bookings_factories.EducationalBookingFactory(
            status=BookingStatus.CONFIRMED, )
        educational_booking = booking.educationalBooking

        # open a second connection on purpose and lock the deposit
        engine = create_engine(app.config["SQLALCHEMY_DATABASE_URI"])
        with engine.connect() as connection:
            connection.execute(
                text(
                    """SELECT * FROM stock WHERE id = :stock_id FOR UPDATE"""),
                stock_id=booking.stock.id,
            )

            with pytest.raises(sqlalchemy.exc.OperationalError):
                educational_api.refuse_educational_booking(
                    educational_booking.id)

        refreshed_booking = Booking.query.filter(
            Booking.id == booking.id).one()
        assert refreshed_booking.status == BookingStatus.CONFIRMED
コード例 #4
0
def refuse_pre_booking(educational_booking_id: int) -> prebooking_serialization.EducationalBookingResponse:
    """Refuse a prebooking confirmation

    Can only work if prebooking is confirmed or pending,
    is not yet used and still refusable."""
    try:
        educational_booking = api.refuse_educational_booking(educational_booking_id)
    except exceptions.EducationalBookingNotFound:
        raise ApiErrors({"code": constants.EDUCATIONAL_BOOKING_NOT_FOUND}, status_code=404)
    except exceptions.EducationalBookingNotRefusable:
        raise ApiErrors({"code": "EDUCATIONAL_BOOKING_NOT_REFUSABLE"}, status_code=422)
    except exceptions.EducationalBookingAlreadyCancelled:
        raise ApiErrors({"code": "EDUCATIONAL_BOOKING_ALREADY_CANCELLED"}, status_code=422)

    return prebooking_serialization.serialize_educational_booking(educational_booking)
コード例 #5
0
 def test_raises_when_no_educational_booking_found(self):
     with pytest.raises(exceptions.EducationalBookingNotFound):
         educational_api.refuse_educational_booking(123)