Пример #1
0
    def test_raise_if_already_booked(self):
        booking = factories.IndividualBookingFactory()

        with pytest.raises(exceptions.OfferIsAlreadyBooked) as error:
            validation.check_offer_already_booked(
                booking.individualBooking.user, booking.stock.offer)
        assert error.value.errors == {
            "offerId": ["Cette offre a déja été reservée par l'utilisateur"]
        }
def create_booking_for_user_on_specific_stock_bypassing_capping_limits(
        user_id: int, stock_id: int) -> None:
    stock = Stock.query.get(stock_id)
    user = User.query.get(user_id)
    quantity = 1

    validation.check_offer_already_booked(user, stock.offer)
    validation.check_quantity(stock.offer, quantity)
    validation.check_can_book_free_offer(user, stock)
    validation.check_stock_is_bookable(stock)

    booking = models.Booking()
    # FIXME: this is not right. PcObject's constructor should allow
    # `Booking(stock=stock, ...)`
    booking.userId = user.id
    booking.stockId = stock.id
    booking.amount = stock.price
    booking.quantity = quantity
    booking.token = random_token()
    repository.save(booking)

    redis.add_offer_id(client=app.redis_client, offer_id=stock.offerId)
Пример #3
0
 def test_dont_raise_if_user_cancelled(self):
     booking = factories.BookingFactory(isCancelled=True)
     validation.check_offer_already_booked(booking.user, booking.stock.offer)  # should not raise
Пример #4
0
 def test_dont_raise_if_user_never_booked_this_offer(self):
     offer = offers_factories.OfferFactory()
     user = users_factories.UserFactory()
     validation.check_offer_already_booked(user, offer)  # should not raise