def test_payment_date_should_return_oldest_payment_date_for_status_sent_if_several( self, app): # Given user = users_factories.UserFactory() booking = create_booking(user=user) today = datetime.utcnow() yesterday = datetime.utcnow() - timedelta(days=1) offerer = booking.stock.offer.venue.managingOfferer payment_message = create_payment_message(name="mon message") payment = create_payment(booking, offerer, 5, payment_message=payment_message) payment_status = create_payment_status( payment, status=TransactionStatus.SENT, date=today) create_payment_status(payment, status=TransactionStatus.SENT, date=yesterday) repository.save(payment_status) # When payment_from_query = Payment.query.with_entities( Payment.lastProcessedDate.label("payment_date")).first() # Then assert payment_from_query.payment_date == yesterday
def test_should_return_one_payment_info_with_sent_status(self, app): # Given user = users_factories.UserFactory(lastName="User", firstName="Plus") offerer = create_offerer(address="7 rue du livre") venue = create_venue(offerer) stock = create_stock_with_thing_offer(offerer=offerer, venue=venue, price=10) now = datetime.utcnow() booking = create_booking(user=user, stock=stock, is_used=True, date_used=now, token="ABCDEF", venue=venue) payment = create_payment( booking, offerer, transaction_label= "pass Culture Pro - remboursement 1ère quinzaine 07-2019", status=TransactionStatus.ERROR, amount=50, detail="Iban non fourni", status_date=now - timedelta(days=2), ) payment_status1 = create_payment_status(payment, detail="All good", status=TransactionStatus.RETRY, date=now - timedelta(days=1)) payment_status2 = create_payment_status(payment, detail="All good", status=TransactionStatus.SENT) repository.save(payment, payment_status1, payment_status2) # When payments = find_all_offerer_payments(offerer.id) # Then assert len(payments) == 1 assert payments[0] == ( "User", "Plus", "ABCDEF", now, "Test Book", "7 rue du livre", "La petite librairie", "12345678912345", "123 rue de Paris", Decimal("50.00"), None, "pass Culture Pro - remboursement 1ère quinzaine 07-2019", TransactionStatus.SENT, "All good", )
def test_should_cancel_reimbursed_and_banned_bookings_with_current_status_banned_and_wanted_dates( self, app): # Given booking = create_booking(stock=self.stock, user=self.beneficiary, date_used=datetime.utcnow(), is_used=True) payment = create_payment(offerer=self.offerer, booking=booking, status=TransactionStatus.SENT, status_date=self.WANTED_SENT_DATETIME) payment_banned_status = create_payment_status( payment=payment, status=TransactionStatus.BANNED, date=self.WANTED_BANNED_DATETIME) payment.statuses.append(payment_banned_status) repository.save(payment) # When cancel_banned_bookings() # Then corrected_booking = Booking.query.get(booking.id) assert corrected_booking.isCancelled is True assert corrected_booking.cancellationDate is not None assert corrected_booking.isUsed is False assert corrected_booking.dateUsed is None
def test_payment_date_should_return_oldest_payment_date_for_status_sent_if_several(self, app): # Given beneficiary = users_factories.BeneficiaryGrant18Factory() booking = booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary) today = datetime.utcnow() yesterday = datetime.utcnow() - timedelta(days=1) payment_message = create_payment_message(name="mon message") payment = create_payment(booking, booking.offerer, 5, payment_message=payment_message) payment_status = create_payment_status(payment, status=TransactionStatus.SENT, date=today) create_payment_status(payment, status=TransactionStatus.SENT, date=yesterday) repository.save(payment_status) # When payment_from_query = Payment.query.with_entities(Payment.lastProcessedDate.label("payment_date")).first() # Then assert payment_from_query.payment_date == yesterday
def test_payment_date_should_return_no_payment_date_for_status_pending(self, app): # Given user = create_user() booking = create_booking(user=user) today = datetime.utcnow() create_deposit(user) offerer = booking.stock.offer.venue.managingOfferer payment_message = create_payment_message(name="mon message") payment = create_payment(booking, offerer, 5, payment_message=payment_message) payment_status = create_payment_status(payment, status=TransactionStatus.PENDING, date=today) repository.save(payment_status) # When payment_from_query = Payment.query.with_entities(Payment.lastProcessedDate.label("payment_date")).first() # Then assert payment_from_query.payment_date is None
def test_should_return_last_matching_status_based_on_date_for_each_payment( self, app): # Given user = users_factories.UserFactory(lastName="User", firstName="Plus") offerer = create_offerer(address="7 rue du livre") venue = create_venue(offerer) stock = create_stock_with_thing_offer(offerer=offerer, venue=venue, price=10) now = datetime.utcnow() booking1 = create_booking(user=user, stock=stock, is_used=True, date_used=now, token="ABCDEF", venue=venue) booking2 = create_booking(user=user, stock=stock, is_used=True, date_used=now, token="ABCDFE", venue=venue) payment1 = create_payment( booking1, offerer, transaction_label= "pass Culture Pro - remboursement 1ère quinzaine 07-2019", status=TransactionStatus.PENDING, amount=50, status_date=now - timedelta(days=2), ) payment2 = create_payment( booking2, offerer, transaction_label= "pass Culture Pro - remboursement 2ème quinzaine 07-2019", status=TransactionStatus.PENDING, amount=75, status_date=now - timedelta(days=4), ) repository.save(payment1, payment2) last_status_for_payment1 = create_payment_status( payment1, detail="All good", status=TransactionStatus.SENT, date=now) last_status_for_payment2 = create_payment_status( payment2, detail=None, status=TransactionStatus.SENT, date=now) repository.save(last_status_for_payment1, last_status_for_payment2) first_status_for_payment1 = create_payment_status( payment1, detail="Retry", status=TransactionStatus.RETRY, date=now - timedelta(days=1)) first_status_for_payment2 = create_payment_status( payment2, detail="Iban non fournis", status=TransactionStatus.ERROR, date=now - timedelta(days=3)) repository.save(first_status_for_payment1, first_status_for_payment2) # When payments = find_all_offerer_payments(offerer.id) # Then assert len(payments) == 2 assert payments[0] == ( "User", "Plus", "ABCDFE", now, "Test Book", "7 rue du livre", "La petite librairie", "12345678912345", "123 rue de Paris", Decimal("75.00"), None, "pass Culture Pro - remboursement 2ème quinzaine 07-2019", TransactionStatus.SENT, None, ) assert payments[1] == ( "User", "Plus", "ABCDEF", now, "Test Book", "7 rue du livre", "La petite librairie", "12345678912345", "123 rue de Paris", Decimal("50.00"), None, "pass Culture Pro - remboursement 1ère quinzaine 07-2019", TransactionStatus.SENT, "All good", )