def create_booking( user: User, amount: Optional[Union[Decimal, float]] = None, date_created: datetime = datetime.utcnow(), date_used: datetime = None, idx: int = None, is_cancelled: bool = False, is_used: bool = False, quantity: int = 1, stock: Stock = None, token: str = None, venue: VenueSQLEntity = None, ) -> Booking: booking = Booking() offerer = create_offerer(siren="987654321", address="Test address", city="Test city", postal_code="93000", name="Test name") if venue is None: venue = create_venue( offerer=offerer, name="Test offerer", booking_email="*****@*****.**", address="123 rue test", postal_code="93000", city="Test city", departement_code="93", ) if stock is None: price = amount if amount is not None else 10 product_with_thing_type = create_offer_with_thing_product(venue) stock = create_stock_with_thing_offer(offerer=offerer, venue=venue, offer=product_with_thing_type, price=price) if not stock.offer: stock.offer = create_offer_with_thing_product(venue) booking.user = user booking.amount = amount if amount is not None else stock.price booking.dateCreated = date_created booking.dateUsed = date_used booking.id = idx booking.isCancelled = is_cancelled booking.isUsed = is_used booking.quantity = quantity booking.stock = stock booking.token = token if token is not None else random_token() booking.userId = user.id booking.confirmationDate = bookings_api.compute_confirmation_date( stock.beginningDatetime, date_created) return booking
def create_booking_for_event( # pylint: disable=redefined-builtin amount: int = 50, date_created: datetime = datetime.utcnow(), is_cancelled: bool = False, quantity: int = 1, type: EventType = EventType.CINEMA, user: User = None, ) -> Booking: 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 = is_cancelled booking.token = random_token() booking.dateCreated = date_created return booking