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'
예제 #3
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
예제 #4
0
    def test_modify_statuses_on_given_payments(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()

        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)

        PcObject.save(deposit, 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
예제 #5
0
        def when_given_checksum_does_not_match_known_checksum(self, app):
            # given
            user = create_user(can_book_free_offers=False, is_admin=True)
            payment_message = create_payment_message(
                name='passCulture-SCT-20181015-114356',
                checksum=b'FAKE_CHECKSUM')
            PcObject.save(user, payment_message)

            auth_request = TestClient(
                app.test_client()).with_auth(email=user.email)

            # when
            response = auth_request.post(
                '/validate/payment_message',
                files={
                    'file':
                    (BytesIO(VALID_MESSAGE.encode('utf-8')), 'message.xml')
                })

            # then
            assert response.status_code == 400
            assert response.json['xml'] == [
                "L'intégrité du document n'est pas validée car la somme de contrôle est invalide : "
                "86055b286afd11316cd7cacd00e61034fddedda50c234c0157a8f0da6e30931e"
            ]
예제 #6
0
        def when_file_authenticity_is_certified(self, app):
            # given
            user = create_user(can_book_free_offers=False, is_admin=True)
            payment_message = create_payment_message(
                name='passCulture-SCT-20181015-114356',
                checksum=
                b'\x86\x05[(j\xfd\x111l\xd7\xca\xcd\x00\xe6\x104\xfd\xde\xdd\xa5\x0c#L\x01W\xa8\xf0\xdan0\x93\x1e'
            )
            PcObject.save(user, payment_message)

            auth_request = TestClient(
                app.test_client()).with_auth(email=user.email)

            # when
            response = auth_request.post(
                '/validate/payment_message',
                files={
                    'file':
                    (BytesIO(VALID_MESSAGE.encode('utf-8')), 'message.xml')
                })

            # then
            assert response.status_code == 200
            assert response.json[
                'checksum'] == '86055b286afd11316cd7cacd00e61034fddedda50c234c0157a8f0da6e30931e'
    def test_returns_none_is_message_id_is_unknown(self, app):
        pass
        # given
        message_id = 'ABCD1234'
        message = create_payment_message(name=message_id)
        PcObject.save(message)

        # when
        checksum = find_message_checksum('EFGH5678')

        # then
        assert checksum is None
    def test_returns_a_checksum_if_message_id_is_known(self, app):
        pass
        # given
        message_id = 'ABCD1234'
        message = create_payment_message(name=message_id)
        PcObject.save(message)

        # when
        checksum = find_message_checksum(message_id)

        # then
        assert checksum == message.checksum
예제 #9
0
        def when_current_user_is_not_admin(self, app):
            # given
            user = create_user(can_book_free_offers=True, is_admin=False)
            message = create_payment_message(
                name='passCulture-SCT-20181015-114356',
                checksum=
                b'\x86\x05[(j\xfd\x111l\xd7\xca\xcd\x00\xe6\x104\xfd\xde\xdd\xa5\x0c#L\x01W\xa8\xf0\xdan0\x93\x1e'
            )
            PcObject.save(user, message)

            auth_request = TestClient(
                app.test_client()).with_auth(email=user.email)

            # when
            response = auth_request.post(
                '/validate/payment_message',
                files={
                    'file':
                    (BytesIO(VALID_MESSAGE.encode('utf-8')), 'message.xml')
                })

            # then
            assert response.status_code == 403