Exemplo n.º 1
0
    def test_file_has_creation_datetime_in_group_header(self, app):
        # Given
        offerer = create_offerer()
        user = create_user()
        venue = create_venue(offerer)
        stock = create_stock_from_offer(create_offer_with_thing_product(venue))
        booking = create_booking(user, stock)
        payment1 = create_payment(booking,
                                  offerer,
                                  Decimal(10),
                                  iban='CF13QSDFGH456789',
                                  bic='QSDFGH8Z555')
        payment2 = create_payment(booking,
                                  offerer,
                                  Decimal(20),
                                  iban='CF13QSDFGH456789',
                                  bic='QSDFGH8Z555')
        payments = [payment1, payment2]

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

        # Then
        assert find_node('//ns:GrpHdr/ns:CreDtTm', xml) == '2018-10-15T09:21:34', \
            'The creation datetime should look like YYYY-MM-DDTHH:MM:SS"'
    def test_returns_payments_with_last_payment_status_retry(self, app):
        # Given
        user = create_user()
        booking = create_booking(user)
        deposit = create_deposit(user)
        offerer = booking.stock.resolvedOffer.venue.managingOfferer
        retry_payment1 = create_payment(booking, offerer, 10)
        retry_payment2 = create_payment(booking, offerer, 10)
        pending_payment = create_payment(booking, offerer, 10, status=TransactionStatus.PENDING)
        retry_status1 = PaymentStatus()
        retry_status1.status = TransactionStatus.RETRY
        retry_payment1.statuses.append(retry_status1)
        retry_status2 = PaymentStatus()
        retry_status2.status = TransactionStatus.RETRY
        retry_payment2.statuses.append(retry_status2)

        PcObject.save(retry_payment1, retry_payment2, pending_payment, deposit)

        # When
        payments = find_retry_payments()

        # Then
        assert len(payments) == 2
        for p in payments:
            assert p.currentStatus.status == TransactionStatus.RETRY
Exemplo n.º 3
0
    def test_file_has_custom_message_id_in_group_header(self, app):
        # Given
        offerer = create_offerer()
        user = create_user()
        venue = create_venue(offerer)
        stock = create_stock_from_offer(create_offer_with_thing_product(venue))
        booking = create_booking(user, stock)
        payment1 = create_payment(booking,
                                  offerer,
                                  Decimal(10),
                                  iban='CF13QSDFGH456789',
                                  bic='QSDFGH8Z555')
        payment2 = create_payment(booking,
                                  offerer,
                                  Decimal(20),
                                  iban='CF13QSDFGH456789',
                                  bic='QSDFGH8Z555')
        payments = [payment1, payment2]

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

        # Then
        assert find_node('//ns:GrpHdr/ns:MsgId', xml) == MESSAGE_ID, \
            'The message id should look like "passCulture-SCT-YYYYMMDD-HHMMSS"'
Exemplo n.º 4
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)
        deposit = create_deposit(user)
        offerer = booking.stock.resolvedOffer.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)

        PcObject.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
Exemplo n.º 5
0
def test_send_transactions_should_send_an_email_with_xml_attachment(app):
    # given
    offerer1 = create_offerer(name='first offerer')
    user = create_user()
    venue1 = create_venue(offerer1)
    stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
    booking1 = create_booking(user, stock1)
    booking2 = create_booking(user, stock1)
    booking3 = create_booking(user, stock1)
    deposit = create_deposit(user, amount=500)
    PcObject.save(deposit)
    payments = [
        create_payment(booking1, offerer1, Decimal(10)),
        create_payment(booking2, offerer1, Decimal(20)),
        create_payment(booking3, offerer1, Decimal(20))
    ]

    app.mailjet_client.send.create.return_value = Mock(status_code=200)

    # when
    send_transactions(payments, 'BD12AZERTY123456', 'AZERTY9Q666', '0000',
                      ['*****@*****.**'])

    # then
    app.mailjet_client.send.create.assert_called_once()
    args = app.mailjet_client.send.create.call_args
    assert len(args[1]['data']['Attachments']) == 1
Exemplo n.º 6
0
    def test_it_returns_only_payments_with_current_status_as_not_processable(
            self):
        # given
        user = create_user()
        booking = create_booking(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
    def test_returns_nothing_if_message_is_not_matched(self, app):
        # given
        user = create_user()
        booking = create_booking(user)
        deposit = create_deposit(user)
        offerer = booking.stock.resolvedOffer.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)
        ]

        PcObject.save(deposit, *payments)

        # when
        matching_payments = find_payments_by_message('unknown message')

        # then
        assert matching_payments == []
    def test_returns_payments_matching_message(self, app):
        # given
        user = create_user()
        booking = create_booking(user)
        deposit = create_deposit(user)
        offerer = booking.stock.resolvedOffer.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)
        ]

        PcObject.save(deposit, *payments)

        # when
        matching_payments = find_payments_by_message('XML1')

        # then
        assert len(matching_payments) == 3
        for p in matching_payments:
            assert p.paymentMessageName == 'XML1'
Exemplo n.º 9
0
def test_read_message_name_in_message_file_returns_the_content_of_message_id_tag(
        app):
    # given
    offerer = create_offerer()
    user = create_user()
    venue = create_venue(offerer)
    stock = create_stock_from_offer(create_offer_with_thing_product(venue))
    booking = create_booking(user, stock)
    payment1 = create_payment(booking,
                              offerer,
                              Decimal(10),
                              iban='CF13QSDFGH456789',
                              bic='QSDFGH8Z555')
    payment2 = create_payment(booking,
                              offerer,
                              Decimal(20),
                              iban='CF13QSDFGH456789',
                              bic='QSDFGH8Z555')
    payments = [payment1, payment2]

    xml_file = generate_message_file(payments, 'BD12AZERTY123456',
                                     'AZERTY9Q666', MESSAGE_ID, '0000')

    # when
    message_id = read_message_name_in_message_file(xml_file)

    # then
    assert message_id == MESSAGE_ID
Exemplo n.º 10
0
    def test_returns_only_payment_total_by_department(self, app):
        # Given
        offerer = create_offerer(siren='111111111')
        venue = create_venue(offerer,
                             postal_code='78490',
                             siret='11111111100002')
        offer = create_offer_with_thing_product(venue)
        stock = create_stock(price=10, offer=offer)

        user_in_35 = create_user(email='*****@*****.**',
                                 departement_code='35')
        user_in_78 = create_user(email='*****@*****.**',
                                 departement_code='78')
        create_deposit(user_in_35, amount=500)
        create_deposit(user_in_78, amount=500)

        booking_in_35 = create_booking(user_in_35, stock=stock, venue=venue)
        booking_in_78 = create_booking(user_in_78, stock=stock, venue=venue)

        payment1 = create_payment(booking_in_35, offerer, amount=20)
        payment2 = create_payment(booking_in_78, offerer, amount=10)

        PcObject.save(user_in_35, venue, payment1, payment2)

        # When
        total_amount_to_pay = get_total_amount_to_pay('35')

        # Then
        assert total_amount_to_pay == 20
Exemplo n.º 11
0
    def test_finds_all_payments_linked_to_offerer(self, app):
        # Given
        offerer = create_offerer()
        other_offerer = create_offerer(siren='987654321')
        venue = create_venue(offerer)
        other_venue = create_venue(other_offerer, siret=other_offerer.siren + '12345')
        bank_information = create_bank_information(offerer=offerer, id_at_providers=offerer.siren)
        other_bank_information = create_bank_information(offerer=other_offerer, id_at_providers=other_venue.siret)
        user = create_user()
        offer = create_offer_with_thing_product(venue)
        other_offer = create_offer_with_thing_product(other_venue)
        stock = create_stock(offer=offer, price=0)
        other_stock = create_stock(offer=other_offer, price=0)
        booking = create_booking(user, stock, venue)
        other_booking = create_booking(user, other_stock, other_venue)
        payment = create_payment(booking, offerer, 10)
        other_payment = create_payment(other_booking, other_offerer, 10)
        payment.setStatus(TransactionStatus.NOT_PROCESSABLE)
        other_payment.setStatus(TransactionStatus.NOT_PROCESSABLE)

        PcObject.save(payment, other_payment)

        # When
        payments = find_all_with_status_not_processable_for_bank_information(bank_information)

        # Then
        assert len(payments) == 1
Exemplo n.º 12
0
    def test_file_has_ultimate_debtor_in_transaction_info(self, app):
        # Given
        offerer = create_offerer()
        user = create_user()
        venue = create_venue(offerer)
        stock = create_stock_from_offer(create_offer_with_thing_product(venue))
        booking = create_booking(user, stock)
        payment1 = create_payment(booking,
                                  offerer,
                                  Decimal(10),
                                  iban='CF13QSDFGH456789',
                                  bic='QSDFGH8Z555')
        payment2 = create_payment(booking,
                                  offerer,
                                  Decimal(20),
                                  iban='CF13QSDFGH456789',
                                  bic='QSDFGH8Z555')
        payments = [payment1, payment2]

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

        # Then
        assert find_node('//ns:PmtInf/ns:CdtTrfTxInf/ns:UltmtDbtr/ns:Nm', xml) == 'pass Culture', \
            'The ultimate debtor name should be "pass Culture"'
Exemplo n.º 13
0
    def test_file_has_initiating_party_in_group_header(self, app):
        # Given
        offerer = create_offerer()
        user = create_user()
        venue = create_venue(offerer)
        stock = create_stock_from_offer(create_offer_with_thing_product(venue))
        booking = create_booking(user, stock)
        payment1 = create_payment(booking,
                                  offerer,
                                  Decimal(10),
                                  iban='CF13QSDFGH456789',
                                  bic='QSDFGH8Z555')
        payment2 = create_payment(booking,
                                  offerer,
                                  Decimal(20),
                                  iban='CF13QSDFGH456789',
                                  bic='QSDFGH8Z555')
        payments = [payment1, payment2]

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

        # Then
        assert find_node('//ns:GrpHdr/ns:InitgPty/ns:Nm', xml) == 'pass Culture', \
            'The initiating party should be "pass Culture"'
Exemplo n.º 14
0
    def test_only_returns_payments_with_given_message(self, app):
        # Given
        offerer = create_offerer()
        venue = create_venue(offerer)
        offer = create_offer_with_thing_product(venue)
        paying_stock = create_stock_from_offer(offer)
        free_stock = create_stock_from_offer(offer, price=0)
        user = create_user()
        deposit = create_deposit(user, amount=500)
        booking1 = create_booking(user, paying_stock, venue, is_used=True)
        booking2 = create_booking(user, paying_stock, venue, is_used=True)
        booking3 = create_booking(user, paying_stock, venue, is_used=True)
        booking4 = create_booking(user, free_stock, venue, is_used=True)
        payment1 = create_payment(booking1, offerer, 10, payment_message_name="ABCD123")
        payment2 = create_payment(booking2, offerer, 10, payment_message_name="EFGH456")

        PcObject.save(payment1, payment2)
        PcObject.save(deposit, booking1, booking3, booking4)

        # When
        payements_by_id = get_payments_by_message_id('ABCD123')

        # Then
        assert len(payements_by_id) == 1
        assert payements_by_id[0].paymentMessage.name == 'ABCD123'
Exemplo n.º 15
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, stock1)
        booking2 = create_booking(user, stock2)
        booking3 = create_booking(user, 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'
Exemplo n.º 16
0
    def test_file_has_bic_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, stock1)
        booking2 = create_booking(user, stock2)
        booking3 = create_booking(user, 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'
Exemplo n.º 17
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}
Exemplo n.º 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 == []
Exemplo n.º 19
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 == []
Exemplo n.º 20
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, stock1)
        booking2 = create_booking(user, stock2)
        booking3 = create_booking(user, 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'
        def test_records_new_payment_lines_in_database(self, app):
            # Given
            offerer = create_offerer()
            venue = create_venue(offerer)
            offer = create_offer_with_thing_product(venue)
            paying_stock = create_stock_from_offer(offer)
            free_stock = create_stock_from_offer(offer, price=0)
            user = create_user()
            deposit = create_deposit(user, amount=500)
            booking1 = create_booking(user, paying_stock, venue, is_used=True)
            booking2 = create_booking(user, paying_stock, venue, is_used=True)
            booking3 = create_booking(user, paying_stock, venue, is_used=True)
            booking4 = create_booking(user, free_stock, venue, is_used=True)
            payment1 = create_payment(booking2,
                                      offerer,
                                      10,
                                      payment_message_name="ABCD123")

            PcObject.save(payment1)
            PcObject.save(deposit, booking1, booking3, booking4)

            initial_payment_count = Payment.query.count()

            # When
            generate_new_payments()

            # Then
            assert Payment.query.count() - initial_payment_count == 2
Exemplo n.º 22
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(price=12, available=5, offer=offer)
        booking = create_booking(user,
                                 stock,
                                 date_created=datetime(2018, 2, 5),
                                 quantity=2,
                                 idx=5)
        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'
Exemplo n.º 23
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(user1), offerer1, 10),
            create_payment(create_booking(user1), offerer1, 20),
            create_payment(create_booking(user2), offerer2, 30)
        ]

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

        # then
        assert len(details) == 3
Exemplo n.º 24
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, stock)
    deposit = create_deposit(user, amount=500)
    payments = [
        create_payment(booking,
                       offerer,
                       Decimal(10),
                       iban='CF  13QSDFGH45 qbc //',
                       bic='QSDFGH8Z555'),
    ]

    PcObject.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"
Exemplo n.º 25
0
def test_send_payments_report_sends_two_csv_attachments_if_no_payments_are_in_error_or_sent(
        app):
    # given
    offerer1 = create_offerer(name='first offerer')
    user = create_user()
    venue1 = create_venue(offerer1)
    stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
    booking1 = create_booking(user, stock1)
    booking2 = create_booking(user, stock1)
    booking3 = create_booking(user, stock1)
    deposit = create_deposit(user, amount=500)
    payments = [
        create_payment(booking1,
                       offerer1,
                       Decimal(10),
                       status=TransactionStatus.SENT,
                       iban='CF13QSDFGH456789',
                       bic='QSDFGH8Z555'),
        create_payment(booking2,
                       offerer1,
                       Decimal(20),
                       status=TransactionStatus.SENT,
                       iban='CF13QSDFGH456789',
                       bic='QSDFGH8Z555'),
        create_payment(booking3,
                       offerer1,
                       Decimal(20),
                       status=TransactionStatus.SENT,
                       iban='CF13QSDFGH456789',
                       bic='QSDFGH8Z555')
    ]

    PcObject.save(deposit)
    PcObject.save(*payments)

    app.mailjet_client.send.create.return_value = Mock(status_code=200)

    # when
    send_payments_report(payments, ['*****@*****.**'])

    # then
    app.mailjet_client.send.create.assert_called_once()
    args = app.mailjet_client.send.create.call_args
    assert len(args[1]['data']['Attachments']) == 2
    assert args[1]['data']['Attachments'][0]['ContentType'] == 'text/csv'
    assert args[1]['data']['Attachments'][1]['ContentType'] == 'text/csv'
Exemplo n.º 26
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, stock1)
        booking2 = create_booking(user, stock2)
        booking3 = create_booking(user, 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'
Exemplo n.º 27
0
def test_generate_file_checksum_returns_a_checksum_of_the_file(
        mocked_uuid, 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, stock1)
    booking2 = create_booking(user, stock2)
    booking3 = create_booking(user, 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')
    ]
    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'
Exemplo n.º 28
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, stock1)
        booking2 = create_booking(user, stock2)
        booking3 = create_booking(user, 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'
Exemplo n.º 29
0
def test_send_transactions_creates_a_new_payment_transaction_if_email_was_sent_properly(
        app):
    # given@
    offerer1 = create_offerer(name='first offerer')
    user = create_user()
    venue1 = create_venue(offerer1)
    stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
    booking1 = create_booking(user, stock1)
    booking2 = create_booking(user, stock1)
    booking3 = create_booking(user, stock1)
    deposit = create_deposit(user, amount=500)
    payments = [
        create_payment(booking1,
                       offerer1,
                       Decimal(10),
                       iban='CF13QSDFGH456789',
                       bic='QSDFGH8Z555'),
        create_payment(booking2,
                       offerer1,
                       Decimal(20),
                       iban='CF13QSDFGH456789',
                       bic='QSDFGH8Z555'),
        create_payment(booking3,
                       offerer1,
                       Decimal(20),
                       iban='CF13QSDFGH456789',
                       bic='QSDFGH8Z555')
    ]

    PcObject.save(deposit)
    PcObject.save(*payments)

    app.mailjet_client.send.create.return_value = Mock(status_code=200)

    # when
    send_transactions(payments, 'BD12AZERTY123456', 'AZERTY9Q666', '0000',
                      ['*****@*****.**'])

    # then
    updated_payments = Payment.query.all()
    assert all(p.paymentMessageName == 'passCulture-SCT-20181015-092134'
               for p in updated_payments)
    assert all(p.paymentMessageChecksum == payments[0].paymentMessageChecksum
               for p in updated_payments)
Exemplo n.º 30
0
def test_send_transactions_set_status_to_error_with_details_if_email_was_not_sent_properly(
        app):
    # given
    offerer1 = create_offerer(name='first offerer')
    user = create_user()
    venue1 = create_venue(offerer1)
    stock1 = create_stock_from_offer(create_offer_with_thing_product(venue1))
    booking1 = create_booking(user, stock1)
    booking2 = create_booking(user, stock1)
    booking3 = create_booking(user, stock1)
    deposit = create_deposit(user, amount=500)
    payments = [
        create_payment(booking1,
                       offerer1,
                       Decimal(10),
                       iban='CF13QSDFGH456789',
                       bic='QSDFGH8Z555'),
        create_payment(booking2,
                       offerer1,
                       Decimal(20),
                       iban='CF13QSDFGH456789',
                       bic='QSDFGH8Z555'),
        create_payment(booking3,
                       offerer1,
                       Decimal(20),
                       iban='CF13QSDFGH456789',
                       bic='QSDFGH8Z555')
    ]

    PcObject.save(deposit)
    PcObject.save(*payments)

    app.mailjet_client.send.create.return_value = Mock(status_code=400)

    # when
    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.ERROR
        assert payment.currentStatus.detail == "Erreur d'envoi à MailJet"