コード例 #1
0
def create_booking_for(user: User, stock: Stock, token: str) -> Booking:
    booking = Booking()
    booking.stock = stock
    booking.user = user
    booking.quantity = 1
    booking.amount = 0
    booking.dateCreated = datetime.utcnow()
    booking.isCancelled = False
    booking.isUsed = False
    booking.token = token
    return booking
コード例 #2
0
    def test_is_cancelled_label_when_booking_is_cancelled(self):
        # Given
        booking = Booking()
        booking.stock = Stock()
        booking.isCancelled = True

        # When
        statusLabel = booking.statusLabel

        # Then
        assert statusLabel == "Réservation annulée"
コード例 #3
0
    def test_raises_resource_gone_error_if_is_cancelled(self):
        # Given
        booking = Booking()
        booking.isUsed = False
        booking.isCancelled = True
        booking.stock = Stock()

        # When
        with pytest.raises(ResourceGoneError) as e:
            check_booking_is_usable(booking)
        assert e.value.errors['booking'] == [
            'Cette réservation a été annulée']
コード例 #4
0
    def test_does_not_raise_error_if_not_cancelled_nor_used_and_no_beginning_datetime(self):
        # Given
        booking = Booking()
        booking.isUsed = False
        booking.isCancelled = False
        booking.stock = Stock()
        booking.stock.beginningDatetime = None

        # When
        try:
            check_booking_is_usable(booking)
        except ApiErrors:
            pytest.fail(
                'Bookings which are not used nor cancelled and do not have a beginning datetime should be usable')
コード例 #5
0
    def test_raises_resource_gone_error_if_stock_beginning_datetime_in_more_than_72_hours(self):
        # Given
        in_four_days = datetime.utcnow() + timedelta(days=4)
        booking = Booking()
        booking.isUsed = False
        booking.isCancelled = False
        booking.stock = Stock()
        booking.stock.beginningDatetime = in_four_days

        # When
        with pytest.raises(ForbiddenError) as e:
            check_booking_is_usable(booking)
        assert e.value.errors['beginningDatetime'] == [
            'Vous ne pouvez pas valider cette contremarque plus de 72h avant le début de l\'évènement']
コード例 #6
0
    def test_does_not_raise_error_if_not_cancelled_nor_used_and_beginning_datetime_in_less_than_72_hours(self):
        # Given
        in_two_days = datetime.utcnow() + timedelta(days=2)
        booking = Booking()
        booking.isUsed = False
        booking.isCancelled = False
        booking.stock = Stock()
        booking.stock.beginningDatetime = in_two_days

        # When
        try:
            check_booking_is_usable(booking)
        except ApiErrors:
            pytest.fail(
                'Bookings which are not used nor cancelled and do not have a beginning datetime should be usable')
コード例 #7
0
ファイル: test_utils.py プロジェクト: Soulou/pass-culture-api
def create_booking_for_thing(
        url=None,
        amount=50,
        quantity=1,
        user=None,
        is_cancelled=False,
        product_type=ThingType.JEUX,
        date_created=datetime.utcnow()
):
    product = Product(from_dict={'url': url, 'type': str(product_type)})
    offer = Offer(from_dict={'type': str(product_type)})
    stock = Stock()
    booking = Booking(from_dict={'amount': amount})
    offer.product = product
    stock.offer = offer
    booking.stock = stock
    booking.quantity = quantity
    booking.user = user
    booking.isCancelled = is_cancelled
    booking.dateCreated = date_created
    return booking
コード例 #8
0
ファイル: test_utils.py プロジェクト: Soulou/pass-culture-api
def create_booking_for_event(
        amount=50,
        quantity=1,
        user=None,
        isCancelled=False,
        type=EventType.CINEMA,
        date_created=datetime.utcnow()
):
    product = Product(from_dict={'type': str(type)})
    offer = Offer()
    stock = Stock()
    booking = Booking(from_dict={'amount': amount})
    offer.product = product
    stock.offer = offer
    booking.stock = stock
    booking.quantity = quantity
    booking.user = user
    booking.isCancelled = isCancelled
    booking.token = random_token()
    booking.dateCreated = date_created
    return booking
コード例 #9
0
ファイル: test_utils.py プロジェクト: Soulou/pass-culture-api
def create_booking(user, stock=None, venue=None, recommendation=None, quantity=1, date_created=datetime.utcnow(),
                   date_used=None, is_cancelled=False, is_used=False, token=None, idx=None, amount=None):
    booking = Booking()
    if venue is None:
        offerer = create_offerer('987654321', 'Test address', 'Test city', '93000', 'Test name')
        venue = create_venue(offerer, 'Test offerer', '*****@*****.**', '123 rue test', '93000', 'Test city',
                             '93')
    if stock is None:
        product_with_thing_type = create_offer_with_thing_product(venue)
        stock = create_stock_with_thing_offer(offerer, venue, product_with_thing_type, price=10)
    booking.stock = stock
    booking.user = user
    if token is None:
        booking.token = random_token()
    else:
        booking.token = token

    if amount is None:
        booking.amount = stock.price
    else:
        booking.amount = amount

    booking.quantity = quantity
    booking.dateCreated = date_created
    if recommendation:
        booking.recommendation = recommendation
    elif not stock.offer:
        offer = create_offer_with_thing_product(venue)
        booking.recommendation = create_recommendation(offer, user)
    else:
        booking.recommendation = create_recommendation(stock.offer, user)
    booking.isCancelled = is_cancelled
    booking.isUsed = is_used
    booking.dateUsed = date_used
    if idx:
        booking.id = idx
    return booking