Beispiel #1
0
    def test_file_has_recipient_name_and_siren_in_creditor_info(self, app):
        # Given
        offerer1 = create_offerer(name="first offerer", siren="123456789")
        offerer2 = create_offerer(name="second offerer", siren="987654321")
        offerer3 = create_offerer()
        user = create_user()
        venue1 = create_venue(offerer1)
        venue2 = create_venue(offerer2)
        venue3 = create_venue(offerer3)
        stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
        stock2 = create_stock_from_offer(create_offer_with_thing_product(venue2))
        stock3 = create_stock_from_offer(create_offer_with_thing_product(venue3))
        booking1 = create_booking(user=user, stock=stock1)
        booking2 = create_booking(user=user, stock=stock2)
        booking3 = create_booking(user=user, stock=stock3)

        payments = [
            create_payment(booking1, offerer1, Decimal(10), iban="CF13QSDFGH456789", bic="QSDFGH8Z555"),
            create_payment(booking2, offerer2, Decimal(20), iban="FR14WXCVBN123456", bic="WXCVBN7B444"),
            create_payment(booking3, offerer3, Decimal(20), iban=None, bic=None),
        ]

        # When
        xml = generate_message_file(payments, "BD12AZERTY123456", "AZERTY9Q666", MESSAGE_ID, "0000")

        # Then
        assert find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:Cdtr/ns:Nm", xml)[0] == "first offerer"
        assert find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:Cdtr/ns:Id/ns:OrgId/ns:Othr/ns:Id", xml)[0] == "123456789"
        assert find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:Cdtr/ns:Nm", xml)[1] == "second offerer"
        assert find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:Cdtr/ns:Id/ns:OrgId/ns:Othr/ns:Id", xml)[1] == "987654321"
Beispiel #2
0
    def test_returns_payments_with_last_payment_status_error(self, app):
        # Given
        user = create_user()
        booking = create_booking(user=user)
        create_deposit(user)
        error_payment1 = create_payment(
            booking,
            booking.stock.offer.venue.managingOfferer,
            10,
            status=TransactionStatus.ERROR)
        error_payment2 = create_payment(
            booking,
            booking.stock.offer.venue.managingOfferer,
            10,
            status=TransactionStatus.ERROR)
        pending_payment = create_payment(
            booking, booking.stock.offer.venue.managingOfferer, 10)
        repository.save(error_payment1, error_payment2, pending_payment)

        # When
        payments = payment_queries.find_error_payments()

        # Then
        assert len(payments) == 2
        for payment in payments:
            assert payment.currentStatus.status == TransactionStatus.ERROR
Beispiel #3
0
    def test_file_has_number_of_transactions_in_payment_info(self, app):
        # Given
        offerer1 = create_offerer()
        offerer2 = create_offerer()
        offerer3 = create_offerer()
        user = create_user()
        venue1 = create_venue(offerer1)
        venue2 = create_venue(offerer2)
        venue3 = create_venue(offerer3)
        stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
        stock2 = create_stock_from_offer(create_offer_with_thing_product(venue2))
        stock3 = create_stock_from_offer(create_offer_with_thing_product(venue3))
        booking1 = create_booking(user=user, stock=stock1)
        booking2 = create_booking(user=user, stock=stock2)
        booking3 = create_booking(user=user, stock=stock3)

        payments = [
            create_payment(booking1, offerer1, Decimal(10), iban="CF13QSDFGH456789", bic="QSDFGH8Z555"),
            create_payment(booking2, offerer2, Decimal(20), iban="FR14WXCVBN123456", bic="WXCVBN7B444"),
            create_payment(booking3, offerer3, Decimal(20), iban=None, bic=None),
        ]

        # When
        xml = generate_message_file(payments, "BD12AZERTY123456", "AZERTY9Q666", MESSAGE_ID, "0000")

        # Then
        assert (
            find_node("//ns:PmtInf/ns:NbOfTxs", xml) == "2"
        ), "The number of transactions should match the distinct number of IBANs"
Beispiel #4
0
    def test_file_has_amount_in_credit_transfer_transaction_info(self, app):
        # Given
        offerer1 = create_offerer(name="first offerer")
        offerer2 = create_offerer(name="second offerer")
        user = create_user()
        venue1 = create_venue(offerer1)
        venue2 = create_venue(offerer2)
        stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
        stock2 = create_stock_from_offer(create_offer_with_thing_product(venue1))
        stock3 = create_stock_from_offer(create_offer_with_thing_product(venue2))
        booking1 = create_booking(user=user, stock=stock1)
        booking2 = create_booking(user=user, stock=stock2)
        booking3 = create_booking(user=user, stock=stock3)

        payments = [
            create_payment(booking1, offerer1, Decimal(10), iban="CF13QSDFGH456789", bic="QSDFGH8Z555"),
            create_payment(booking2, offerer1, Decimal(20), iban="CF13QSDFGH456789", bic="QSDFGH8Z555"),
            create_payment(booking3, offerer2, Decimal(20), iban="FR14WXCVBN123456", bic="WXCVBN7B444"),
        ]

        # When
        xml = generate_message_file(payments, "BD12AZERTY123456", "AZERTY9Q666", MESSAGE_ID, "0000")

        # Then
        nodes_amount = find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:Amt/ns:InstdAmt", xml)
        assert nodes_amount[0] == "30"
        assert nodes_amount[1] == "20"
    def test_returns_payments_with_last_payment_status_retry(self, app):
        # Given
        user = users_factories.UserFactory()
        booking = create_booking(user=user)
        offerer = booking.stock.offer.venue.managingOfferer
        retry_payment1 = create_payment(booking,
                                        offerer,
                                        10,
                                        status=TransactionStatus.RETRY)
        retry_payment2 = create_payment(booking,
                                        offerer,
                                        10,
                                        status=TransactionStatus.RETRY)
        pending_payment = create_payment(booking,
                                         offerer,
                                         10,
                                         status=TransactionStatus.PENDING)
        repository.save(retry_payment1, retry_payment2, pending_payment)

        # When
        payments = payment_queries.find_retry_payments()

        # Then
        assert len(payments) == 2
        for payment in payments:
            assert payment.currentStatus.status == TransactionStatus.RETRY
    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 == []
Beispiel #7
0
    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
Beispiel #8
0
    def test_it_returns_only_payments_with_current_status_as_not_processable(
            self):
        # given
        user = create_user()
        booking = create_booking(user=user)
        offerer = create_offerer()
        payments = [
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.PENDING),
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.NOT_PROCESSABLE),
            create_payment(booking,
                           offerer,
                           30,
                           status=TransactionStatus.ERROR),
        ]

        # when
        pending_payments = keep_only_not_processable_payments(payments)

        # then
        assert len(pending_payments) == 1
        assert pending_payments[
            0].currentStatus.status == TransactionStatus.NOT_PROCESSABLE
Beispiel #9
0
    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_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"
Beispiel #11
0
    def test_file_has_control_sum_in_group_header(self, app):
        # Given
        user = create_user()
        offerer1 = create_offerer()
        offerer2 = create_offerer()
        venue1 = create_venue(offerer1)
        venue2 = create_venue(offerer2)
        stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
        stock2 = create_stock_from_offer(create_offer_with_thing_product(venue2))
        booking1 = create_booking(user=user, stock=stock1)
        booking2 = create_booking(user=user, stock=stock2)

        payments = [
            create_payment(booking1, offerer1, Decimal(10), iban="CF13QSDFGH456789", bic="QSDFGH8Z555"),
            create_payment(booking1, offerer1, Decimal(20), iban="CF13QSDFGH456789", bic="QSDFGH8Z555"),
            create_payment(booking2, offerer2, Decimal(30), iban=None, bic=None),
        ]

        # When
        xml = generate_message_file(payments, "BD12AZERTY123456", "AZERTY9Q666", MESSAGE_ID, "0000")

        # Then
        assert (
            find_node("//ns:GrpHdr/ns:CtrlSum", xml) == "30"
        ), "The control sum should match the total amount of money to pay"
Beispiel #12
0
    def test_file_has_hexadecimal_uuids_as_end_to_end_ids_in_transaction_info(self, mocked_uuid, app):
        # Given
        user = create_user()
        offerer1 = create_offerer(name="first offerer")
        offerer2 = create_offerer(name="second offerer")
        venue1 = create_venue(offerer1)
        venue2 = create_venue(offerer2)
        stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
        stock2 = create_stock_from_offer(create_offer_with_thing_product(venue2))
        booking1 = create_booking(user=user, stock=stock1)
        booking2 = create_booking(user=user, stock=stock2)
        uuid1 = UUID(hex="abcd1234abcd1234abcd1234abcd1234", version=4)
        uuid2 = UUID(hex="cdef5678cdef5678cdef5678cdef5678", version=4)
        mocked_uuid.side_effect = [uuid1, uuid2]

        payments = [
            create_payment(booking1, offerer1, Decimal(10), iban="CF13QSDFGH456789", bic="QSDFGH8Z555"),
            create_payment(booking2, offerer1, Decimal(20), iban="FR14WXCVBN123456", bic="WXCVBN7B444"),
        ]

        # When
        xml = generate_message_file(payments, "BD12AZERTY123456", "AZERTY9Q666", MESSAGE_ID, "0000")

        # Then
        nodes_id = find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:PmtId/ns:EndToEndId", xml)
        assert nodes_id[0] == uuid1.hex
        assert nodes_id[1] == uuid2.hex
Beispiel #13
0
    def test_file_has_iban_in_credit_transfer_transaction_info(self, app):
        # Given
        offerer1 = create_offerer()
        offerer2 = create_offerer()
        offerer3 = create_offerer()
        user = create_user()
        venue1 = create_venue(offerer1)
        venue2 = create_venue(offerer2)
        venue3 = create_venue(offerer3)
        stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
        stock2 = create_stock_from_offer(create_offer_with_thing_product(venue2))
        stock3 = create_stock_from_offer(create_offer_with_thing_product(venue3))
        booking1 = create_booking(user=user, stock=stock1)
        booking2 = create_booking(user=user, stock=stock2)
        booking3 = create_booking(user=user, stock=stock3)

        payments = [
            create_payment(booking1, offerer1, Decimal(10), iban="CF13QSDFGH456789", bic="QSDFGH8Z555"),
            create_payment(booking2, offerer2, Decimal(20), iban="FR14WXCVBN123456", bic="WXCVBN7B444"),
            create_payment(booking3, offerer3, Decimal(20), iban=None, bic=None),
        ]

        # When
        xml = generate_message_file(payments, "BD12AZERTY123456", "AZERTY9Q666", MESSAGE_ID, "0000")

        # Then
        assert find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:CdtrAcct/ns:Id/ns:IBAN", xml)[0] == "CF13QSDFGH456789"
        assert find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:CdtrAcct/ns:Id/ns:IBAN", xml)[1] == "FR14WXCVBN123456"
Beispiel #14
0
    def test_file_has_transaction_label_in_credit_transfer_transaction_info(self, app):
        # Given
        offerer1 = create_offerer(name="first offerer")
        offerer2 = create_offerer(name="second offerer")
        offerer3 = create_offerer(name="third offerer")
        user = create_user()
        venue1 = create_venue(offerer1)
        venue2 = create_venue(offerer2)
        venue3 = create_venue(offerer3)
        stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
        stock2 = create_stock_from_offer(create_offer_with_thing_product(venue2))
        stock3 = create_stock_from_offer(create_offer_with_thing_product(venue3))
        booking1 = create_booking(user=user, stock=stock1)
        booking2 = create_booking(user=user, stock=stock2)
        booking3 = create_booking(user=user, stock=stock3)

        payments = [
            create_payment(
                booking1,
                offerer1,
                Decimal(10),
                iban="CF13QSDFGH456789",
                bic="QSDFGH8Z555",
                transaction_label="remboursement 1ère quinzaine 09-2018",
            ),
            create_payment(
                booking2,
                offerer2,
                Decimal(20),
                iban="FR14WXCVBN123456",
                bic="WXCVBN7B444",
                transaction_label="remboursement 1ère quinzaine 09-2018",
            ),
            create_payment(
                booking3,
                offerer3,
                Decimal(20),
                iban=None,
                bic=None,
                transaction_label="remboursement 1ère quinzaine 09-2018",
            ),
        ]

        # When
        xml = generate_message_file(payments, "BD12AZERTY123456", "AZERTY9Q666", MESSAGE_ID, "0000")

        # Then
        assert (
            find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:RmtInf/ns:Ustrd", xml)[0]
            == "remboursement 1ère quinzaine 09-2018"
        )
        assert (
            find_all_nodes("//ns:PmtInf/ns:CdtTrfTxInf/ns:RmtInf/ns:Ustrd", xml)[1]
            == "remboursement 1ère quinzaine 09-2018"
        )
Beispiel #15
0
def test_generate_file_checksum_returns_a_checksum_of_the_file(mocked_uuid, app):
    # given
    offerer1 = create_offerer(name="first offerer", siren="123456789")
    offerer2 = create_offerer(name="second offerer", siren="123456789")
    user = create_user()
    venue1 = create_venue(offerer1)
    venue2 = create_venue(offerer2)
    stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
    stock2 = create_stock_from_offer(create_offer_with_thing_product(venue1))
    stock3 = create_stock_from_offer(create_offer_with_thing_product(venue2))
    booking1 = create_booking(user=user, stock=stock1)
    booking2 = create_booking(user=user, stock=stock2)
    booking3 = create_booking(user=user, stock=stock3)

    payments = [
        create_payment(
            booking1,
            offerer1,
            Decimal(10),
            iban="CF13QSDFGH456789",
            bic="QSDFGH8Z555",
            transaction_label="pass Culture Pro - remboursement 2nde quinzaine 07-2018",
        ),
        create_payment(
            booking2,
            offerer1,
            Decimal(20),
            iban="CF13QSDFGH456789",
            bic="QSDFGH8Z555",
            transaction_label="pass Culture Pro - remboursement 2nde quinzaine 07-2018",
        ),
        create_payment(
            booking3,
            offerer2,
            Decimal(20),
            iban="FR14WXCVBN123456",
            bic="WXCVBN7B444",
            transaction_label="pass Culture Pro - remboursement 2nde quinzaine 07-2018",
        ),
    ]
    uuid1 = UUID(hex="abcd1234abcd1234abcd1234abcd1234", version=4)
    uuid2 = UUID(hex="cdef5678cdef5678cdef5678cdef5678", version=4)
    mocked_uuid.side_effect = [uuid1, uuid2]

    xml = generate_message_file(payments, "BD12AZERTY123456", "AZERTY9Q666", MESSAGE_ID, "0000")

    # when
    checksum = generate_file_checksum(xml)

    # then
    assert checksum == b"\x16\x91\x0c\x11~Hs\xc5\x1a\xa3W1\x13\xbf!jq@\xea  <h&\xef\x1f\xaf\xfc\x7fO\xc8\x82"
Beispiel #16
0
    def test_value_error_is_raised_if_payments_ids_do_not_match_payments(self):
        # given
        payments = [
            create_payment(Booking(), Offerer(), 10, idx=111),
            create_payment(Booking(), Offerer(), 10, idx=222),
        ]
        ids_to_ban = [222, 333]

        # when
        with pytest.raises(UnmatchedPayments) as e:
            apply_banishment(payments, ids_to_ban)

        # then
        assert e.value.payment_ids == {333}
Beispiel #17
0
    def test_no_payments_to_retry_if_all_are_banned(self):
        # given
        payments = [
            create_payment(Booking(), Offerer(), 10, idx=111),
            create_payment(Booking(), Offerer(), 10, idx=222),
        ]
        ids_to_ban = [111, 222]

        # when
        banned_payments, retry_payments = apply_banishment(
            payments, ids_to_ban)

        # then
        assert len(banned_payments) == 2
        assert retry_payments == []
Beispiel #18
0
    def test_no_payments_are_returned_if_no_ids_are_provided(self):
        # given
        payments = [
            create_payment(Booking(), Offerer(), 10, idx=111),
            create_payment(Booking(), Offerer(), 10, idx=222),
        ]
        ids_to_ban = []

        # when
        banned_payments, retry_payments = apply_banishment(
            payments, ids_to_ban)

        # then
        assert banned_payments == []
        assert retry_payments == []
Beispiel #19
0
    def test_returns_as_much_payment_details_as_there_are_payments_given(self):
        # given
        offerer1, offerer2 = create_offerer(), create_offerer()
        user1, user2 = create_user(), create_user()
        payments = [
            create_payment(create_booking(user=user1), offerer1, 10),
            create_payment(create_booking(user=user1), offerer1, 20),
            create_payment(create_booking(user=user2), offerer2, 30),
        ]

        # when
        details = create_all_payments_details(payments,
                                              find_booking_date_used=Mock())

        # then
        assert len(details) == 3
Beispiel #20
0
    def test_contains_info_on_offer(self):
        # given
        user = create_user(email="*****@*****.**", idx=3)
        offerer = create_offerer(siren="987654321", name="Joe le Libraire")
        venue = create_venue(offerer,
                             name="Jack le Sculpteur",
                             siret="1234567891234")
        offer = create_offer_with_thing_product(venue)
        stock = create_stock(offer=offer, price=12, quantity=5)
        booking = create_booking(user=user,
                                 stock=stock,
                                 date_created=datetime(2018, 2, 5),
                                 idx=5,
                                 quantity=2)
        payment = create_payment(booking, offerer, 35)
        find_date = Mock()
        find_date.return_value = datetime(2018, 2, 19)

        # when
        details = create_payment_details(payment,
                                         find_booking_date_used=find_date)

        # then
        assert details.offer_name == "Test Book"
        assert details.offer_type == "Audiovisuel - films sur supports physiques et VOD"
Beispiel #21
0
    def test_contains_info_on_venue(self):
        # given
        user = create_user(email="*****@*****.**", idx=3)
        offerer = create_offerer(siren="987654321", name="Joe le Libraire")
        venue = create_venue(offerer,
                             name="Jack le Sculpteur",
                             siret="1234567891234",
                             idx=1)
        offer = create_offer_with_thing_product(venue)
        stock = create_stock(offer=offer, price=12, quantity=5)
        booking = create_booking(user=user,
                                 stock=stock,
                                 date_created=datetime(2018, 2, 5),
                                 idx=5,
                                 quantity=2)
        payment = create_payment(booking, offerer, 35)
        find_date = Mock()
        find_date.return_value = datetime(2018, 2, 19)

        # when
        details = create_payment_details(payment,
                                         find_booking_date_used=find_date)

        # then
        assert details.venue_name == "Jack le Sculpteur"
        assert details.venue_siret == "1234567891234"
        assert details.venue_humanized_id == humanize(venue.id)
Beispiel #22
0
    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 when_api_key_is_provided_and_booking_payment_exists(self, app):
            # Given
            user = create_user()
            pro_user = create_user(email="*****@*****.**")
            offerer = create_offerer()
            user_offerer = create_user_offerer(pro_user, offerer)
            venue = create_venue(offerer)
            stock = create_stock_with_event_offer(offerer, venue, price=0)

            booking = create_booking(user=user, stock=stock, venue=venue, is_used=True)
            payment = create_payment(booking, offerer, Decimal(10), iban="CF13QSDFGH456789", bic="QSDFGH8Z555")

            repository.save(booking, user_offerer, payment)

            offererApiKey = create_api_key(offerer_id=offerer.id)
            repository.save(offererApiKey)

            # When
            url = "/v2/bookings/keep/token/{}".format(booking.token)
            user2_api_key = "Bearer " + offererApiKey.value

            response = TestClient(app.test_client()).patch(
                url, headers={"Authorization": user2_api_key, "Origin": "http://localhost"}
            )
            # Then
            assert response.status_code == 410
            assert response.json["payment"] == ["Le remboursement est en cours de traitement"]
            assert Booking.query.get(booking.id).isUsed is True
    def test_generate_payment_csv_raw_contains_human_readable_status_with_details_when_error(
            self, app):
        # given
        user = users_factories.UserFactory(email="*****@*****.**")
        offerer = create_offerer()
        venue = create_venue(offerer)
        stock = create_stock_with_thing_offer(offerer=offerer,
                                              venue=venue,
                                              price=10)
        booking = create_booking(user=user,
                                 stock=stock,
                                 is_used=True,
                                 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",
        )
        repository.save(payment)

        payments_info = find_all_offerer_payments(offerer.id)

        # when
        raw_csv = ReimbursementDetails(payments_info[0]).as_csv_row()

        # then
        assert raw_csv[
            13] == "Erreur d'envoi du remboursement : Iban non fourni"
    def test_should_return_payment_to_retry_if_bank_information_linked_to_venue_and_current_status_is_not_processable(
            self, app):
        # Given
        offerer = create_offerer()
        user = users_factories.UserFactory()
        venue = create_venue(offerer)
        stock = create_stock_from_offer(create_offer_with_thing_product(venue),
                                        price=0)
        booking = create_booking(user=user, stock=stock)
        not_processable_payment = create_payment(
            booking,
            offerer,
            10,
            status=TransactionStatus.NOT_PROCESSABLE,
            iban="CF13QSDFGH456789",
            bic="QSDFGH8Z555")
        bank_information = create_bank_information(venue=venue)
        repository.save(not_processable_payment, bank_information)

        # When
        payments_to_retry = payment_queries.find_not_processable_with_bank_information(
        )

        # Then
        assert not_processable_payment in payments_to_retry
Beispiel #26
0
def test_send_transactions_with_malformed_iban_on_payments_gives_them_an_error_status_with_a_cause(
        app):
    # given
    offerer = create_offerer(name="first offerer")
    user = create_user()
    venue = create_venue(offerer)
    stock = create_stock_from_offer(create_offer_with_thing_product(venue))
    booking = create_booking(user=user, stock=stock)
    deposit = create_deposit(user, amount=500)
    payments = [
        create_payment(booking,
                       offerer,
                       10,
                       iban="CF  13QSDFGH45 qbc //",
                       bic="QSDFGH8Z555"),
    ]

    repository.save(deposit, *payments)
    app.mailjet_client.send.create.return_value = Mock(status_code=400)

    # when
    with pytest.raises(DocumentInvalid):
        send_transactions(payments, "BD12AZERTY123456", "AZERTY9Q666", "0000",
                          ["*****@*****.**"])

    # then
    updated_payments = Payment.query.all()
    for payment in updated_payments:
        assert len(payment.statuses) == 2
        assert payment.currentStatus.status == TransactionStatus.NOT_PROCESSABLE
        assert (
            payment.currentStatus.detail ==
            "Element '{urn:iso:std:iso:20022:tech:xsd:pain.001.001.03}IBAN': "
            "[facet 'pattern'] The value 'CF  13QSDFGH45 qbc //' is not accepted "
            "by the pattern '[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}'., line 76")
Beispiel #27
0
    def test_should_return_cancelled_booking_with_payment(self, app):
        # Given
        beneficiary = create_user()
        create_deposit(user=beneficiary)
        offerer = create_offerer()
        venue = create_venue(offerer)
        offer = create_offer_with_event_product(venue)
        stock1 = create_stock(beginning_datetime=datetime(2020, 4, 16),
                              offer=offer)
        stock2 = create_stock(beginning_datetime=datetime(2020, 4, 16),
                              offer=offer)
        booking1 = create_booking(stock=stock1,
                                  user=beneficiary,
                                  is_cancelled=True)
        booking2 = create_booking(stock=stock2,
                                  user=beneficiary,
                                  is_cancelled=True)
        payment = create_payment(offerer=offerer, booking=booking1)

        repository.save(payment, booking2)

        # When
        bookings_result = get_bookings_cancelled_during_quarantine_with_payment(
        )

        # Then
        assert bookings_result == [booking1]
Beispiel #28
0
    def test_should_not_revert_booking_dateused_if_booking_already_has_one(
            self, stub_get_bookings_cancelled_during_quarantine_with_payment,
            app):
        # Given
        dateused = datetime(2020, 7, 3, 20, 4, 4)
        beneficiary = create_user()
        create_deposit(user=beneficiary)
        offerer = create_offerer()
        venue = create_venue(offerer)
        offer = create_offer_with_event_product(venue)
        stock = create_stock(beginning_datetime=datetime(2020, 4, 16),
                             offer=offer)
        booking = create_booking(
            stock=stock,
            user=beneficiary,
            is_cancelled=True,
            date_created=datetime(2019, 7, 3, 20, 4, 4),
            date_used=dateused,
        )
        payment = create_payment(offerer=offerer, booking=booking)
        repository.save(payment)

        stub_get_bookings_cancelled_during_quarantine_with_payment.return_value = [
            booking
        ]

        # When
        correct_booking_status()

        # Then
        corrected_booking = Booking.query.get(booking.id)
        assert corrected_booking.isCancelled is False
        assert corrected_booking.cancellationDate is None
        assert corrected_booking.isUsed is True
        assert corrected_booking.dateUsed == dateused
        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
Beispiel #30
0
    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"