Exemple #1
0
 def test_raise_if_already_cancelled(self):
     booking = factories.BookingFactory(
         isCancelled=True,
         cancellationReason=BookingCancellationReasons.BENEFICIARY)
     with pytest.raises(api_errors.ResourceGoneError):
         api.cancel_booking_by_offerer(booking)
     assert booking.isCancelled
     assert booking.cancellationReason == BookingCancellationReasons.BENEFICIARY
Exemple #2
0
    def test_raise_if_already_used(self):
        booking = factories.BookingFactory(isUsed=True)
        with pytest.raises(api_errors.ForbiddenError):
            api.cancel_booking_by_offerer(booking)
        assert booking.isUsed
        assert not booking.isCancelled
        assert not booking.cancellationReason

        assert not booking.isCancelled
    def test_raise_if_already_used(self):
        booking = booking_factories.UsedIndividualBookingFactory()
        with pytest.raises(api_errors.ForbiddenError):
            api.cancel_booking_by_offerer(booking)
        assert booking.isUsed
        assert not booking.isCancelled
        assert booking.status is BookingStatus.USED
        assert not booking.cancellationReason

        assert push_testing.requests == []
    def test_raise_if_already_cancelled(self):
        booking = booking_factories.CancelledIndividualBookingFactory(
            cancellationReason=BookingCancellationReasons.BENEFICIARY
        )
        with pytest.raises(api_errors.ResourceGoneError):
            api.cancel_booking_by_offerer(booking)
        assert booking.isCancelled
        assert booking.status is BookingStatus.CANCELLED
        assert booking.cancellationReason == BookingCancellationReasons.BENEFICIARY  # unchanged

        assert push_testing.requests == []
Exemple #5
0
def soft_delete_stock(stock_id):
    stock = Stock.query.filter(Stock.id == stock_id).first()
    bookings = _get_bookings_for_stock(stock_id)
    can_soft_delete = _check_bookings(bookings)

    if can_soft_delete:
        print(
            f"Soft-deleting stock {stock} and cancelling {len(bookings)} bookings..."
        )
        for booking in bookings:
            bookings_api.cancel_booking_by_offerer(booking)
            print(f"Cancelled {booking}")
        print(f"Soft-deleted {stock}")
        stock.isSoftDeleted = True
        repository.save(stock)
        print("Done")
Exemple #6
0
def patch_cancel_booking_by_token(token: str):
    """Let a pro user cancel a booking."""
    valid_api_key = _get_api_key_from_header(request)
    token = token.upper()
    booking = booking_repository.find_by(token=token)
    offerer_id = booking.stock.offer.venue.managingOffererId

    if current_user.is_authenticated:
        ensure_current_user_has_rights(RightsType.editor, offerer_id)

    if valid_api_key:
        check_api_key_allows_to_cancel_booking(valid_api_key, offerer_id)

    bookings_api.cancel_booking_by_offerer(booking)

    return "", 204
def patch_cancel_booking_by_token(token: str) -> None:
    # in French, to be used by Swagger for the API documentation
    """Annulation d'une réservation.

    Bien que, dans le cas d’un événement, l’utilisateur ne peut plus annuler sa réservation 72h avant le début de ce dernier,
    cette API permet d’annuler la réservation d’un utilisateur si elle n’a pas encore été validé.
    """
    token = token.upper()
    booking = booking_repository.find_by(token=token)

    if current_user.is_authenticated:
        check_user_has_access_to_offerer(current_user, booking.offererId)

    if current_api_key:
        check_api_key_allows_to_cancel_booking(
            current_api_key,  # type: ignore[arg-type]
            booking.offererId,
        )

    bookings_api.cancel_booking_by_offerer(booking)
    def test_cancel(self):
        booking = booking_factories.IndividualBookingFactory()

        api.cancel_booking_by_offerer(booking)

        # cancellation can trigger more than one request to Batch
        assert len(push_testing.requests) >= 1

        assert booking.isCancelled
        assert booking.status is BookingStatus.CANCELLED
        assert booking.cancellationReason == BookingCancellationReasons.OFFERER

        cancel_notification_request = next(
            req for req in push_testing.requests if req.get("group_id") == "Cancel_booking"
        )
        assert cancel_notification_request == {
            "group_id": "Cancel_booking",
            "message": {
                "body": f"""Ta commande "{booking.stock.offer.name}" a été annulée par l\'offreur.""",
                "title": "Commande annulée",
            },
            "user_ids": [booking.individualBooking.userId],
        }
Exemple #9
0
 def test_cancel(self):
     booking = factories.BookingFactory()
     api.cancel_booking_by_offerer(booking)
     assert booking.isCancelled
     assert booking.cancellationReason == BookingCancellationReasons.OFFERER