コード例 #1
0
def check_is_usable(booking: Booking) -> None:
    booking_payment = payment_queries.find_by_booking_id(booking.id)
    if booking_payment is not None:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("payment", "Cette réservation a été remboursée")
        raise forbidden

    if booking.isUsed:
        gone = api_errors.ResourceGoneError()
        gone.add_error("booking", "Cette réservation a déjà été validée")
        raise gone

    if booking.isCancelled:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("booking", "Cette réservation a été annulée")
        raise forbidden

    is_booking_for_event_and_not_confirmed = booking.stock.beginningDatetime and not booking.isConfirmed
    if is_booking_for_event_and_not_confirmed:
        forbidden = api_errors.ForbiddenError()
        booking_date = datetime.datetime.strftime(booking.dateCreated,
                                                  "%d/%m/%Y à %H:%M")
        max_cancellation_date = datetime.datetime.strftime(
            api.compute_confirmation_date(booking.stock.beginningDatetime,
                                          booking.dateCreated),
            "%d/%m/%Y à %H:%M")

        forbidden.add_error(
            "booking",
            f"Cette réservation a été effectuée le {booking_date}. "
            f"Veuillez attendre jusqu’au {max_cancellation_date} pour valider la contremarque.",
        )
        raise forbidden
コード例 #2
0
def check_is_usable(booking: Booking) -> None:
    if payment_queries.has_payment(booking):
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("payment", "Cette réservation a été remboursée")
        raise forbidden

    if booking.isUsed or booking.status is BookingStatus.USED:
        gone = api_errors.ResourceGoneError()
        gone.add_error("booking", "Cette réservation a déjà été validée")
        raise gone

    if booking.isCancelled or booking.status is BookingStatus.CANCELLED:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("booking", "Cette réservation a été annulée")
        raise forbidden

    if booking.educationalBookingId is not None:
        if booking.educationalBooking.status is EducationalBookingStatus.REFUSED:
            reason = "Cette réservation pour une offre éducationnelle a été refusée par le chef d'établissement"
            raise api_errors.ForbiddenError(errors={"educationalBooking": reason})

        if booking.educationalBooking.status is not EducationalBookingStatus.USED_BY_INSTITUTE:
            reason = (
                "Cette réservation pour une offre éducationnelle n'est pas encore validée par le chef d'établissement"
            )
            raise api_errors.ForbiddenError(errors={"educationalBooking": reason})

    is_booking_for_event_and_not_confirmed = booking.stock.beginningDatetime and not booking.isConfirmed
    if is_booking_for_event_and_not_confirmed:
        forbidden = api_errors.ForbiddenError()
        venue_departement_code = booking.venue.departementCode
        booking_date = datetime.datetime.strftime(
            utc_datetime_to_department_timezone(booking.dateCreated, venue_departement_code), "%d/%m/%Y à %H:%M"
        )
        max_cancellation_date = datetime.datetime.strftime(
            utc_datetime_to_department_timezone(
                api.compute_cancellation_limit_date(
                    booking.stock.beginningDatetime,
                    booking.dateCreated,
                ),
                venue_departement_code,
            ),
            "%d/%m/%Y à %H:%M",
        )

        forbidden.add_error(
            "booking",
            f"Cette réservation a été effectuée le {booking_date}. "
            f"Veuillez attendre jusqu’au {max_cancellation_date} pour valider la contremarque.",
        )
        raise forbidden
コード例 #3
0
def check_booking_can_be_cancelled(booking: Booking) -> None:
    if booking.isCancelled or booking.status == BookingStatus.CANCELLED:
        gone = api_errors.ResourceGoneError()
        gone.add_error("global", "Cette contremarque a déjà été annulée")
        raise gone
    if booking.isUsed or booking.status == BookingStatus.USED:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("global", "Impossible d'annuler une réservation consommée")
        raise forbidden
コード例 #4
0
def check_offerer_can_cancel_booking(booking: Booking) -> None:
    if booking.isCancelled:
        gone = api_errors.ResourceGoneError()
        gone.add_error("global", "Cette contremarque a déjà été annulée")
        raise gone
    if booking.isUsed:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("global",
                            "Impossible d'annuler une réservation consommée")
        raise forbidden
コード例 #5
0
def check_can_be_mark_as_unused(booking: Booking) -> None:
    if (
        booking.stock.canHaveActivationCodes
        and booking.activationCode
        and FeatureToggle.AUTO_ACTIVATE_DIGITAL_BOOKINGS.is_active()
    ):
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("booking", "Cette réservation ne peut pas être marquée comme inutilisée")
        raise forbidden

    if booking.isCancelled:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("booking", "Cette réservation a été annulée")
        raise forbidden

    if payment_queries.has_payment(booking):
        gone = api_errors.ResourceGoneError()
        gone.add_error("payment", "Le remboursement est en cours de traitement")
        raise gone

    if not booking.isUsed:
        gone = api_errors.ResourceGoneError()
        gone.add_error("booking", "Cette réservation n'a pas encore été validée")
        raise gone
コード例 #6
0
    def when_booking_not_confirmed(self, mocked_check_is_usable, app):
        # Given
        next_week = datetime.utcnow() + timedelta(weeks=1)
        booking = BookingFactory(stock__beginningDatetime=next_week)
        pro_user = UserFactory(email="*****@*****.**")
        offerer = booking.stock.offer.venue.managingOfferer
        offers_factories.UserOffererFactory(user=pro_user, offerer=offerer)
        url = "/bookings/token/{}".format(booking.token)
        mocked_check_is_usable.side_effect = api_errors.ForbiddenError(errors={"booking": ["Not confirmed"]})

        # When
        response = TestClient(app.test_client()).with_auth("*****@*****.**").patch(url)

        # Then
        assert response.status_code == 403
        assert response.json["booking"] == ["Not confirmed"]
コード例 #7
0
        def when_booking_not_confirmed(self, mocked_check_is_usable, app):
            # Given
            next_week = datetime.utcnow() + timedelta(weeks=1)
            unconfirmed_booking = BookingFactory(
                stock__beginningDatetime=next_week)
            url = (
                f"/bookings/token/{unconfirmed_booking.token}?email={unconfirmed_booking.user.email}"
                f"&offer_id={humanize(unconfirmed_booking.stock.offerId)}")
            mocked_check_is_usable.side_effect = api_errors.ForbiddenError(
                errors={"booking": ["Not confirmed"]})

            # When
            response = TestClient(app.test_client()).get(url)

            # Then
            assert response.status_code == 403
            assert response.json["booking"] == ["Not confirmed"]
コード例 #8
0
def check_can_be_mark_as_unused(booking: Booking) -> None:
    if not booking.isUsed:
        gone = api_errors.ResourceGoneError()
        gone.add_error("booking",
                       "Cette réservation n'a pas encore été validée")
        raise gone

    if booking.isCancelled:
        forbidden = api_errors.ForbiddenError()
        forbidden.add_error("booking", "Cette réservation a été annulée")
        raise forbidden

    booking_payment = payment_queries.find_by_booking_id(booking.id)
    if booking_payment is not None:
        gone = api_errors.ResourceGoneError()
        gone.add_error("payment",
                       "Le remboursement est en cours de traitement")
        raise gone