def test_modify_statuses_on_given_payments(self, app): # given user = users_factories.UserFactory() booking = create_booking(user=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() payment1 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1) payment2 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid2, payment_message=transaction2) payment3 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction3) payment4 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid3, payment_message=transaction1) payment5 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1) payment6 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1) repository.save(payment1, payment2, payment3, payment4, payment5, payment6) # when do_ban_payments("XML1", [payment1.id, payment5.id]) # then assert payment1.currentStatus.status == TransactionStatus.BANNED assert payment2.currentStatus.status == TransactionStatus.PENDING assert payment3.currentStatus.status == TransactionStatus.PENDING assert payment4.currentStatus.status == TransactionStatus.RETRY assert payment5.currentStatus.status == TransactionStatus.BANNED assert payment6.currentStatus.status == TransactionStatus.RETRY
def test_does_not_modify_statuses_on_given_payments_if_a_payment_id_is_not_found( self, app): # given booking = booking_factories.IndividualBookingFactory() offerer = booking.offerer transaction1 = create_payment_message(name="XML1") transaction2 = create_payment_message(name="XML2") uuid1, uuid2 = uuid.uuid4(), uuid.uuid4() payment1 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1) payment2 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid2, payment_message=transaction2) repository.save(payment1, payment2) # when do_ban_payments("XML1", [payment1.id, 123456]) # then assert payment1.currentStatus.status == TransactionStatus.PENDING assert payment2.currentStatus.status == TransactionStatus.PENDING
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 test_does_not_modify_statuses_on_given_payments_if_a_payment_id_is_not_found( self, app): # given user = create_user() booking = create_booking(user=user) deposit = create_deposit(user) offerer = booking.stock.offer.venue.managingOfferer transaction1 = create_payment_message(name="XML1") transaction2 = create_payment_message(name="XML2") uuid1, uuid2 = uuid.uuid4(), uuid.uuid4() payment1 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid1, payment_message=transaction1) payment2 = create_payment(booking, offerer, 5, transaction_end_to_end_id=uuid2, payment_message=transaction2) repository.save(deposit, payment1, payment2) # when do_ban_payments("XML1", [payment1.id, 123456]) # then assert payment1.currentStatus.status == TransactionStatus.PENDING assert payment2.currentStatus.status == TransactionStatus.PENDING
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_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 == []
def test_payment_date_should_return_payment_date_for_status_sent(self, app): # Given beneficiary = users_factories.BeneficiaryGrant18Factory() booking = booking_factories.IndividualBookingFactory(individualBooking__user=beneficiary) today = datetime.utcnow() 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) 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 == today
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