Example #1
0
    def test_raise_if_not_bookable(self):
        yesterday = datetime.now() - timedelta(days=1)
        stock = offers_factories.StockFactory(bookingLimitDatetime=yesterday)

        with pytest.raises(exceptions.StockIsNotBookable) as error:
            validation.check_stock_is_bookable(stock)
        assert error.value.errors == {"stock": ["Ce stock n'est pas réservable"]}
Example #2
0
    def test_raise_if_duo_not_bookable(self):
        stock_quantity = 1
        booking_quantity = 2
        offer = offers_factories.OfferFactory(isDuo=True)
        stock = offers_factories.StockFactory(offer=offer,
                                              quantity=stock_quantity)

        with pytest.raises(exceptions.StockIsNotBookable) as error:
            validation.check_stock_is_bookable(stock, booking_quantity)
        assert error.value.errors == {
            "stock": ["Ce stock n'est pas réservable"]
        }
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)
Example #4
0
 def test_dont_raise_if_bookable(self):
     stock = offers_factories.StockFactory()
     validation.check_stock_is_bookable(stock)  # should not raise