def test_quantity_update_with_cancellations_exceed_quantity(self): # Given stock = factories.ThingStockFactory(quantity=2) bookings_factories.CancelledBookingFactory(stock=stock) bookings_factories.CancelledBookingFactory(stock=stock) bookings_factories.BookingFactory(stock=stock) bookings_factories.BookingFactory(stock=stock) # When stock.quantity = 3 repository.save(stock) # Then assert Stock.query.get(stock.id).quantity == 3
def test_bookings_quantity_with_a_cancelled_booking(self): offer = factories.OfferFactory( product__subcategoryId=subcategories.ACHAT_INSTRUMENT.id) stock = factories.StockFactory(offer=offer, quantity=5) bookings_factories.BookingFactory(stock=stock) bookings_factories.CancelledBookingFactory(stock=stock) assert Stock.query.filter(Stock.dnBookedQuantity == 1).one() == stock
def test_stock_with_positive_remaining_quantity_after_cancelled_booking( self): offer = factories.OfferFactory() stock = factories.StockFactory(offer=offer, quantity=5) bookings_factories.CancelledBookingFactory(stock=stock) assert stock.remainingQuantity == 5 assert Offer.query.filter(Stock.remainingQuantity == 5).one() == offer
def test_when_booking_is_cancelled(self, client): # Given booking = bookings_factories.CancelledBookingFactory() pro_user = offers_factories.UserOffererFactory(offerer=booking.offerer).user # When url = f"/v2/bookings/token/{booking.token}" response = client.with_basic_auth(pro_user.email).get(url) # Then assert response.status_code == 403 assert response.json["booking"] == ["Cette réservation a été annulée"]
def when_booking_has_been_cancelled_already(self, app): # Given admin = users_factories.AdminFactory() booking = bookings_factories.CancelledBookingFactory() url = f"/bookings/token/{booking.token}" # When response = TestClient(app.test_client()).with_session_auth(admin.email).patch(url) # Then assert response.status_code == 403 assert response.json["booking"] == ["Cette réservation a été annulée"] assert Booking.query.get(booking.id).isUsed is False
def test_cancel_a_booking_already_cancelled(self, client): # Given booking = bookings_factories.CancelledBookingFactory() pro_user = offers_factories.UserOffererFactory( offerer=booking.offerer).user # When url = f"/v2/bookings/cancel/token/{booking.token}" response = client.with_basic_auth(pro_user.email).patch(url) # Then assert response.status_code == 410 assert response.json["global"] == [ "Cette contremarque a déjà été annulée" ]
def test_when_user_is_logged_in_and_booking_has_been_cancelled_already( self, client): # Given admin = users_factories.AdminFactory() booking = bookings_factories.CancelledBookingFactory() url = f"/v2/bookings/use/token/{booking.token}" # When response = client.with_session_auth(admin.email).patch(url) # Then assert response.status_code == 403 assert response.json["booking"] == [ "Cette réservation a été annulée" ] booking = Booking.query.get(booking.id) assert not booking.isUsed assert booking.status is not BookingStatus.USED
def test_when_api_key_is_provided_and_booking_has_been_cancelled_already( self, client): # Given booking = bookings_factories.CancelledBookingFactory() ApiKeyFactory(offerer=booking.offerer) # When url = f"/v2/bookings/use/token/{booking.token}" auth = "Bearer development_prefix_clearSecret" response = client.patch(url, headers={"Authorization": auth}) # Then assert response.status_code == 403 assert response.json["booking"] == [ "Cette réservation a été annulée" ] booking = Booking.query.get(booking.id) assert not booking.isUsed assert booking.status is not BookingStatus.USED
def test_when_api_key_is_provided_and_booking_has_been_cancelled_already( self, client): # Given booking = bookings_factories.CancelledBookingFactory() ApiKeyFactory(offerer=booking.offerer) # When url = f"/v2/bookings/keep/token/{booking.token}" auth = f"Bearer {DEFAULT_CLEAR_API_KEY}" response = client.patch(url, headers={"Authorization": auth}) # Then booking = Booking.query.get(booking.id) assert response.status_code == 403 assert response.json["booking"] == [ "Cette réservation a été annulée" ] assert not booking.isUsed assert booking.status is BookingStatus.CANCELLED
def test_should_not_return_booking_when_favorite_offer_booking_is_cancelled( self, app): # given beneficiary = users_factories.UserFactory() stock = offers_factories.StockFactory() bookings_factories.CancelledBookingFactory( stock=stock, user=beneficiary, ) offer = stock.offer mediation = offers_factories.MediationFactory(offer=offer) favorite = users_factories.FavoriteFactory(mediation=mediation, offer=offer, user=beneficiary) # when favorites = repository.find_favorites_domain_by_beneficiary( beneficiary.id) # then assert len(favorites) == 1 favorite = favorites[0] assert favorite.is_booked is False
def test_thing_return_none_if_booking_is_cancelled(self): booking = factories.CancelledBookingFactory( stock__offer__subcategoryId=subcategories.JEU_SUPPORT_PHYSIQUE.id, ) assert booking.qrCode is None
def test_event_return_none_if_booking_is_cancelled(self): booking = factories.CancelledBookingFactory( stock__offer__subcategoryId=subcategories.SEANCE_CINE.id, ) assert booking.qrCode is None