def test_returns_nothing_if_message_is_not_matched(self, app): # given user = users_factories.UserFactory() booking = create_booking(user=user) offerer = booking.stock.offer.venue.managingOfferer message1 = create_payment_message(name="XML1") message2 = create_payment_message(name="XML2") message3 = create_payment_message(name="XML3") uuid1, uuid2, uuid3 = uuid.uuid4(), uuid.uuid4(), uuid.uuid4() payments = [ create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=message1), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid2, payment_message=message2), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid3, payment_message=message3), ] repository.save(*payments) # when matching_payments = payment_queries.find_payments_by_message( "unknown message") # then assert matching_payments == []
def test_returns_payments_matching_message(self, app): # given beneficiary = users_factories.BeneficiaryGrant18Factory() booking = bookings_factories.IndividualBookingFactory(individualBooking__user=beneficiary) offerer = booking.offerer transaction1 = create_payment_message(name="XML1") transaction2 = create_payment_message(name="XML2") transaction3 = create_payment_message(name="XML3") uuid1, uuid2, uuid3 = uuid.uuid4(), uuid.uuid4(), uuid.uuid4() payments = [ create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid2, payment_message=transaction2), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction3), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid3, payment_message=transaction1), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1), ] repository.save(*payments) # when matching_payments = payment_queries.find_payments_by_message("XML1") # then assert len(matching_payments) == 3 for payment in matching_payments: assert payment.paymentMessageName == "XML1"
def do_ban_payments(message_id: str, payment_ids_to_ban: list[int]): matching_payments = find_payments_by_message(message_id) try: banned_payments, retry_payments = apply_banishment(matching_payments, payment_ids_to_ban) except UnmatchedPayments as e: logger.exception( "Le message %s ne contient pas les paiements : %s. Aucun paiement n'a été mis à jour.", message_id, e.payment_ids, ) else: if banned_payments: repository.save(*(banned_payments + retry_payments)) logger.info("Paiements bannis : %s ", [p.id for p in banned_payments]) logger.info("Paiements à réessayer : %s ", [p.id for p in retry_payments])
def test_returns_payments_matching_message(self, app): # given user = create_user() booking = create_booking(user=user) create_deposit(user) offerer = booking.stock.offer.venue.managingOfferer transaction1 = create_payment_message(name="XML1") transaction2 = create_payment_message(name="XML2") transaction3 = create_payment_message(name="XML3") uuid1, uuid2, uuid3 = uuid.uuid4(), uuid.uuid4(), uuid.uuid4() payments = [ create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid2, payment_message=transaction2), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction3), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid3, payment_message=transaction1), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1), ] repository.save(*payments) # when matching_payments = payment_queries.find_payments_by_message("XML1") # then assert len(matching_payments) == 3 for payment in matching_payments: assert payment.paymentMessageName == "XML1"
def test_returns_nothing_if_message_is_not_matched(self, app): # given beneficiary = users_factories.BeneficiaryGrant18Factory() booking = bookings_factories.IndividualBookingFactory(individualBooking__user=beneficiary) offerer = booking.offerer message1 = create_payment_message(name="XML1") message2 = create_payment_message(name="XML2") message3 = create_payment_message(name="XML3") uuid1, uuid2, uuid3 = uuid.uuid4(), uuid.uuid4(), uuid.uuid4() payments = [ create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=message1), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid2, payment_message=message2), create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid3, payment_message=message3), ] repository.save(*payments) # when matching_payments = payment_queries.find_payments_by_message("unknown message") # then assert matching_payments == []