def should_return_only_most_recent_booking_when_two_cancelled_on_same_stock( self, app): # Given now = datetime.utcnow() two_days_ago = now - timedelta(days=2) three_days_ago = now - timedelta(days=3) user = create_user() create_deposit(user) offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) stock = create_stock(offer=offer) booking1 = create_booking(user=user, date_created=two_days_ago, is_cancelled=True, stock=stock) booking2 = create_booking(user=user, date_created=three_days_ago, is_cancelled=True, stock=stock) repository.save(booking1, booking2) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings( beneficiary_id=user.id) # Then assert len(result.bookings) == 1 assert result.bookings[0].id == booking1.id
def should_not_return_activation_bookings(self, app): # Given user = create_user() create_deposit(user) offerer = create_offerer() venue = create_venue(offerer) offer1 = create_offer_with_event_product( venue, event_type="ThingType.ACTIVATION") offer2 = create_offer_with_event_product( venue, event_type="EventType.ACTIVATION") offer3 = create_offer_with_event_product(venue, event_type="ThingType.ANY") stock1 = create_stock(offer=offer1) stock2 = create_stock(offer=offer2) stock3 = create_stock(offer=offer3) booking1 = create_booking(user=user, stock=stock1) booking2 = create_booking(user=user, stock=stock2) booking3 = create_booking(user=user, stock=stock3) repository.save(booking1, booking2, booking3) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings( beneficiary_id=user.id) # Then assert len(result.bookings) == 1 assert result.bookings[0].id == booking3.id
def setup_method(self): self.beneficiary_bookings_repository = BeneficiaryBookingsSQLRepository( ) self.beneficiary_bookings_repository.get_beneficiary_bookings = MagicMock( ) self.get_bookings_for_beneficiary = GetBookingsForBeneficiary( beneficiary_bookings_repository=self. beneficiary_bookings_repository)
def should_return_beneficiary_bookings_with_expected_information( self, app): # Given user = create_user() offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_thing_product(venue, url="http://url.com", thumb_count=1) stock = create_stock(offer=offer, price=0) booking = create_booking( user=user, stock=stock, token="ABCDEF", date_created=datetime(2020, 4, 22, 0, 0), date_used=datetime(2020, 5, 5, 0, 0), is_used=True, quantity=2, ) repository.save(booking) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings( beneficiary_id=user.id) # Then assert isinstance(result, BeneficiaryBookingsWithStocks) assert len(result.bookings) == 1 expected_booking = result.bookings[0] assert expected_booking.amount == 0.0 assert expected_booking.cancellationDate is None assert expected_booking.dateCreated == datetime(2020, 4, 22, 0, 0) assert expected_booking.dateUsed == datetime(2020, 5, 5, 0, 0) assert expected_booking.id == booking.id assert expected_booking.isCancelled is False assert expected_booking.isUsed is True assert expected_booking.quantity == 2 assert expected_booking.stockId == stock.id assert expected_booking.token == booking.token assert expected_booking.userId == user.id assert expected_booking.offerId == offer.id assert expected_booking.name == offer.name assert expected_booking.type == offer.type assert expected_booking.url == offer.url assert expected_booking.email == user.email assert expected_booking.beginningDatetime == stock.beginningDatetime assert expected_booking.venueId == venue.id assert expected_booking.departementCode == venue.departementCode assert expected_booking.thumb_url == f"http://localhost/storage/thumbs/products/{humanize(offer.productId)}"
def test_should_return_bookings_by_beneficiary_id(self, app): # Given beneficiary_1 = BeneficiaryGrant18Factory() beneficiary_2 = BeneficiaryGrant18Factory() offer = EventOfferFactory() stock = EventStockFactory(offer=offer) booking1 = booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary_1, stock=stock) booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary_2, stock=stock) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings(beneficiary_id=beneficiary_1.id) # Then assert len(result.bookings) == 1 assert result.bookings[0].id == booking1.id
def should_return_bookings_by_beneficiary_id(self, app): # Given user1 = UserFactory() user2 = UserFactory() offerer = create_offerer() venue = create_venue(offerer) offer = create_offer_with_event_product(venue) stock = create_stock(offer=offer) booking1 = create_booking(user=user1, stock=stock) booking2 = create_booking(user=user2, stock=stock) repository.save(booking1, booking2) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings(beneficiary_id=user1.id) # Then assert len(result.bookings) == 1 assert result.bookings[0].id == booking1.id
def test_should_not_return_activation_bookings(self, app): # Given beneficiary = BeneficiaryGrant18Factory() offer1 = EventOfferFactory(subcategoryId=subcategories.ACTIVATION_THING.id) offer2 = EventOfferFactory(subcategoryId=subcategories.ACTIVATION_THING.id) offer3 = EventOfferFactory(subcategoryId=subcategories.SUPPORT_PHYSIQUE_FILM.id) stock1 = EventStockFactory(offer=offer1) stock2 = EventStockFactory(offer=offer2) stock3 = EventStockFactory(offer=offer3) booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary, stock=stock1) booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary, stock=stock2) booking3 = booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary, stock=stock3) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings(beneficiary_id=beneficiary.id) # Then assert len(result.bookings) == 1 assert result.bookings[0].id == booking3.id
def test_should_return_beneficiary_bookings_with_expected_information(self, app): # Given beneficiary = BeneficiaryGrant18Factory() offer = ThingOfferFactory(isActive=True, url="http://url.com", product__thumbCount=1) stock = ThingStockFactory(offer=offer, price=0, quantity=10) booking = booking_factories.UsedIndividualBookingFactory( individualBooking__user=beneficiary, stock=stock, token="ABCDEF", dateCreated=datetime(2020, 4, 22, 0, 0), dateUsed=datetime(2020, 5, 5, 0, 0), quantity=2, ) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings(beneficiary_id=beneficiary.id) # Then assert isinstance(result, BeneficiaryBookingsWithStocks) assert len(result.bookings) == 1 expected_booking = result.bookings[0] assert expected_booking.amount == 0.0 assert expected_booking.cancellationDate is None assert expected_booking.dateCreated == datetime(2020, 4, 22, 0, 0) assert expected_booking.dateUsed == datetime(2020, 5, 5, 0, 0) assert expected_booking.id == booking.id assert expected_booking.isCancelled is False assert expected_booking.isUsed is True assert expected_booking.quantity == 2 assert expected_booking.stockId == stock.id assert expected_booking.token == booking.token assert expected_booking.userId == beneficiary.id assert expected_booking.offerId == stock.offer.id assert expected_booking.name == stock.offer.name assert expected_booking.url == stock.offer.url assert expected_booking.email == beneficiary.email assert expected_booking.beginningDatetime == stock.beginningDatetime assert expected_booking.venueId == stock.offer.venue.id assert expected_booking.departementCode == stock.offer.venue.departementCode assert ( expected_booking.thumb_url == f"http://localhost/storage/thumbs/products/{humanize(stock.offer.productId)}" )
def test_should_return_only_most_recent_booking_when_two_cancelled_on_same_stock(self, app): # Given now = datetime.utcnow() two_days_ago = now - timedelta(days=2) three_days_ago = now - timedelta(days=3) beneficiary = BeneficiaryGrant18Factory() offer = EventOfferFactory() stock = EventStockFactory(offer=offer) booking1 = booking_factories.CancelledIndividualBookingFactory( individualBooking__user=beneficiary, stock=stock, dateCreated=two_days_ago ) booking_factories.CancelledIndividualBookingFactory( individualBooking__user=beneficiary, stock=stock, dateCreated=three_days_ago ) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings(beneficiary_id=beneficiary.id) # Then assert len(result.bookings) == 1 assert result.bookings[0].id == booking1.id
def should_return_bookings(self, app): # Given now = datetime.utcnow() two_days = now + timedelta(days=2, hours=10) two_days_bis = now + timedelta(days=2, hours=20) three_days = now + timedelta(days=3) user = UserFactory() booking1 = factories.BookingFactory( user=user, stock=EventStockFactory( beginningDatetime=three_days, bookingLimitDatetime=now, ), ) booking2 = factories.BookingFactory( user=user, stock=EventStockFactory( beginningDatetime=two_days, bookingLimitDatetime=now, ), ) booking3 = factories.BookingFactory( user=user, stock=EventStockFactory( beginningDatetime=two_days_bis, bookingLimitDatetime=now, ), ) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings( beneficiary_id=user.id) # Then assert len(result.bookings) == 3 assert set(booking.id for booking in result.bookings) == { booking1.id, booking2.id, booking3.id }
def test_should_return_bookings(self, app): # Given now = datetime.utcnow() two_days = now + timedelta(days=2, hours=10) two_days_bis = now + timedelta(days=2, hours=20) three_days = now + timedelta(days=3) beneficiary = BeneficiaryGrant18Factory() booking1 = booking_factories.IndividualBookingFactory( individualBooking__user=beneficiary, stock=EventStockFactory( beginningDatetime=three_days, bookingLimitDatetime=now, ), ) booking2 = booking_factories.IndividualBookingFactory( individualBooking__user=beneficiary, stock=EventStockFactory( beginningDatetime=two_days, bookingLimitDatetime=now, ), ) booking3 = booking_factories.IndividualBookingFactory( individualBooking__user=beneficiary, stock=EventStockFactory( beginningDatetime=two_days_bis, bookingLimitDatetime=now, ), ) # When result = BeneficiaryBookingsSQLRepository().get_beneficiary_bookings(beneficiary_id=beneficiary.id) # Then assert len(result.bookings) == 3 assert set(booking.id for booking in result.bookings) == {booking1.id, booking2.id, booking3.id}
from pcapi.infrastructure.repository.stock_provider.stock_provider_fnac import StockProviderFnacRepository from pcapi.infrastructure.repository.stock_provider.stock_provider_libraires import StockProviderLibrairesRepository from pcapi.infrastructure.repository.stock_provider.stock_provider_praxiel import StockProviderPraxielRepository from pcapi.infrastructure.repository.stock_provider.stock_provider_titelive import StockProviderTiteLiveRepository from pcapi.infrastructure.repository.venue.venue_label.venue_label_sql_repository import VenueLabelSQLRepository from pcapi.infrastructure.repository.venue.venue_with_basic_information.venue_with_basic_information_sql_repository import ( VenueWithBasicInformationSQLRepository, ) from pcapi.infrastructure.repository.venue.venue_with_offerer_name.venue_with_offerer_name_sql_repository import ( VenueWithOffererNameSQLRepository, ) from pcapi.use_cases.get_bookings_for_beneficiary import GetBookingsForBeneficiary from pcapi.use_cases.get_venue_labels import GetVenueLabels from pcapi.use_cases.get_venues_by_pro_user import GetVenuesByProUser from pcapi.use_cases.list_favorites_of_beneficiary import ListFavoritesOfBeneficiary from pcapi.use_cases.list_offerers_for_pro_user import ListOfferersForProUser beneficiary_bookings_repository = BeneficiaryBookingsSQLRepository() favorite_repository = FavoriteSQLRepository() venue_label_repository = VenueLabelSQLRepository() venue_identifier_repository = VenueWithBasicInformationSQLRepository() venue_with_offerer_informations_repository = VenueWithOffererNameSQLRepository( ) paginated_offerers_repository = PaginatedOfferersSQLRepository() api_libraires_stocks = StockProviderLibrairesRepository() api_fnac_stocks = StockProviderFnacRepository() api_titelive_stocks = StockProviderTiteLiveRepository() api_praxiel_stocks = StockProviderPraxielRepository() # Usecases get_venue_labels = GetVenueLabels( venue_label_repository=venue_label_repository)