예제 #1
0
 def should_pass_when_event_begins_in_more_than_72_hours_and_booking_created_more_than_48_hours_ago(
         self):
     next_week = datetime.utcnow() + timedelta(weeks=1)
     three_days_ago = datetime.utcnow() - timedelta(days=3)
     booking = factories.IndividualBookingFactory(
         stock__beginningDatetime=next_week, dateCreated=three_days_ago)
     validation.check_is_usable(booking)
예제 #2
0
 def should_raise_if_cancelled(self):
     booking = factories.CancelledIndividualBookingFactory()
     with pytest.raises(api_errors.ForbiddenError) as exc:
         validation.check_is_usable(booking)
     assert exc.value.errors["booking"] == [
         "Cette réservation a été annulée"
     ]
예제 #3
0
 def should_raise_if_used(self):
     booking = factories.UsedIndividualBookingFactory()
     with pytest.raises(api_errors.ResourceGoneError) as exc:
         validation.check_is_usable(booking)
     assert exc.value.errors["booking"] == [
         "Cette réservation a déjà été validée"
     ]
예제 #4
0
 def should_raises_forbidden_error_if_payement_exists(self, app):
     booking = factories.UsedIndividualBookingFactory()
     payments_factories.PaymentFactory(booking=booking)
     with pytest.raises(api_errors.ForbiddenError) as exc:
         validation.check_is_usable(booking)
     assert exc.value.errors["payment"] == [
         "Cette réservation a été remboursée"
     ]
예제 #5
0
def get_booking_by_token(token: str) -> tuple[str, int]:
    email: Optional[str] = request.args.get("email", None)
    offer_id = dehumanize(request.args.get("offer_id", None))

    check_user_is_logged_in_or_email_is_provided(current_user, email)

    booking = booking_repository.find_by(token, email, offer_id)
    bookings_validation.check_is_usable(booking)

    if check_user_can_validate_bookings(current_user, booking.offererId):
        response = _create_response_to_get_booking_by_token(booking)
        return jsonify(response), 200

    return "", 204
예제 #6
0
    def should_not_validate_when_event_booking_not_confirmed(self):
        # Given
        next_week = datetime.utcnow() + timedelta(weeks=1)
        one_day_before = datetime.utcnow() - timedelta(days=1)
        booking = factories.BookingFactory(dateCreated=one_day_before, stock__beginningDatetime=next_week)

        # When
        with pytest.raises(api_errors.ForbiddenError) as exception:
            validation.check_is_usable(booking)

        # Then
        assert exception.value.errors["booking"] == [
            "Cette réservation a été effectuée le 14/10/2020 à 09:00. Veuillez "
            "attendre jusqu’au 16/10/2020 à 09:00 pour valider la contremarque."
        ]
예제 #7
0
def get_booking_by_token(token: str):
    email = request.args.get("email", None)
    offer_id = dehumanize(request.args.get("offer_id", None))

    check_user_is_logged_in_or_email_is_provided(current_user, email)

    booking_token_upper_case = token.upper()
    booking = booking_repository.find_by(booking_token_upper_case, email,
                                         offer_id)
    bookings_validation.check_is_usable(booking)

    if check_user_can_validate_bookings(
            current_user, booking.stock.offer.venue.managingOffererId):
        response = _create_response_to_get_booking_by_token(booking)
        return jsonify(response), 200

    return "", 204
예제 #8
0
def get_booking_by_token_v2(token: str):
    valid_api_key = _get_api_key_from_header(request)
    booking_token_upper_case = token.upper()
    booking = booking_repository.find_by(token=booking_token_upper_case)
    offerer_id = booking.stock.offer.venue.managingOffererId

    if current_user.is_authenticated:
        # warning : current user is not none when user is not logged in
        check_user_can_validate_bookings_v2(current_user, offerer_id)

    if valid_api_key:
        check_api_key_allows_to_validate_booking(valid_api_key, offerer_id)

    bookings_validation.check_is_usable(booking)

    response = serialize_booking(booking)

    return jsonify(response), 200
예제 #9
0
    def should_use_timezone_of_venue_departmentCode(self):
        # Given
        next_week = datetime.utcnow() + timedelta(weeks=1)
        one_day_before = datetime.utcnow() - timedelta(days=1)

        booking = factories.IndividualBookingFactory(
            dateCreated=one_day_before,
            stock__beginningDatetime=next_week,
            stock__offer__venue__postalCode="97300")

        # When
        with pytest.raises(api_errors.ForbiddenError) as exception:
            validation.check_is_usable(booking)

        # Then
        assert exception.value.errors["booking"] == [
            "Cette réservation a été effectuée le 14/10/2020 à 06:00. Veuillez "
            "attendre jusqu’au 16/10/2020 à 06:00 pour valider la contremarque."
        ]
예제 #10
0
def get_booking_by_token_v2(token: str) -> GetBookingResponse:
    # in French, to be used by Swagger for the API documentation
    """Consultation d'une réservation.

    Le code “contremarque” ou "token" est une chaîne de caractères permettant d’identifier la réservation et qui sert de preuve de réservation.
    Ce code unique est généré pour chaque réservation d'un utilisateur sur l'application et lui est transmis à cette occasion.
    """
    booking = booking_repository.find_by(token=token)

    if current_user.is_authenticated:
        # warning : current user is not none when user is not logged in
        check_user_can_validate_bookings_v2(current_user, booking.offererId)

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

    bookings_validation.check_is_usable(booking)

    return get_booking_response(booking)
예제 #11
0
 def should_pass_when_event_begins_in_less_than_48_hours(self):
     soon = datetime.utcnow() + timedelta(hours=48)
     booking = factories.BookingFactory(stock__beginningDatetime=soon)
     validation.check_is_usable(booking)
예제 #12
0
 def should_pass_if_no_beginning_datetime(self):
     booking = factories.BookingFactory(stock__beginningDatetime=None)
     validation.check_is_usable(booking)