コード例 #1
0
ファイル: test_receipt.py プロジェクト: nitheesh-aot/sbc-pay
def test_create_receipt_without_invoice(session, public_user_mock):
    """Try creating a receipt without invoice number."""
    payment_account = factory_payment_account()
    payment = factory_payment()
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment.id, payment_account.id)
    invoice.save()
    factory_invoice_reference(invoice.id).save()
    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')
    line = factory_payment_line_item(
        invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
    line.save()
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    PaymentService.update_payment(payment.id, get_payment_request())
    input_data = {
        'corpName': 'Pennsular Coop ',
        'filingDateTime': '1999',
        'fileName': 'coopser'
    }
    response = ReceiptService.create_receipt(payment.id,
                                             '',
                                             input_data,
                                             skip_auth_check=True)
    assert response is not None
コード例 #2
0
ファイル: test_receipt.py プロジェクト: nitheesh-aot/sbc-pay
def test_create_receipt_with_no_receipt(session, public_user_mock):
    """Try creating a receipt with invoice number."""
    payment_account = factory_payment_account()
    payment = factory_payment()
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment.id, payment_account.id)
    invoice.save()
    factory_invoice_reference(invoice.id).save()
    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')
    line = factory_payment_line_item(
        invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
    line.save()

    PaymentService.update_payment(payment.id, get_payment_request())
    input_data = {
        'corpName': 'Pennsular Coop ',
        'filingDateTime': '1999',
        'fileName': 'coopser'
    }

    with pytest.raises(BusinessException) as excinfo:
        ReceiptService.create_receipt(payment.id,
                                      '',
                                      input_data,
                                      skip_auth_check=True)
    assert excinfo.type == BusinessException
コード例 #3
0
def test_update_payment_cancel_invalid(session):
    """Assert that the payment records are updated."""
    payment_account = factory_payment_account()
    payment = factory_payment()
    payment_account.save()
    payment.payment_status_code = Status.CANCELLED.value
    payment.save()
    invoice = factory_invoice(payment.id, payment_account.id)
    invoice.save()
    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')
    line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
    line.save()
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    with pytest.raises(BusinessException) as excinfo:
        PaymentService.update_payment(payment.id, get_payment_request(), 'test')
    assert excinfo.type == BusinessException
コード例 #4
0
def test_update_payment_deleted_invalid(session, public_user_mock):
    """Assert that the payment records are not updated."""
    payment_account = factory_payment_account()
    payment = factory_payment()
    payment_account.save()
    payment.payment_status_code = PaymentStatus.DELETED.value
    payment.save()
    invoice = factory_invoice(payment, payment_account)
    invoice.save()
    factory_invoice_reference(invoice.id).save()

    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')
    line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
    line.save()
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    with pytest.raises(BusinessException) as excinfo:
        PaymentService.update_payment(payment.id, get_payment_request(), get_auth_basic_user())
    assert excinfo.type == BusinessException
コード例 #5
0
def test_update_payment_record_transaction_invalid(session):
    """Assert that the payment records are updated."""
    payment_account = factory_payment_account()
    payment = factory_payment()
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment.id, payment_account.id)
    invoice.save()
    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')
    line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
    line.save()
    transaction = factory_payment_transaction(payment.id, Status.COMPLETED.value)
    transaction.save()

    payment_response = PaymentService.update_payment(payment.id, get_payment_request(), 'test')
    assert payment_response.get('id') is not None
コード例 #6
0
def test_update_payment_record(session, public_user_mock):
    """Assert that the payment records are updated."""
    payment_account = factory_payment_account()
    payment = factory_payment()
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment, payment_account)
    invoice.save()
    factory_invoice_reference(invoice.id).save()
    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')
    line = factory_payment_line_item(invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
    line.save()
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    payment_response = PaymentService.update_payment(payment.id, get_payment_request(), get_auth_basic_user())
    assert payment_response.get('id') is not None
コード例 #7
0
def test_update_payment_record_rollback(session):
    """Assert that the payment records are updated."""
    payment_account = factory_payment_account()
    payment = factory_payment()
    payment_account.save()
    payment.save()
    invoice = factory_invoice(payment.id, payment_account.id)
    invoice.save()
    fee_schedule = FeeSchedule.find_by_filing_type_and_corp_type('CP', 'OTANN')
    line = factory_payment_line_item(
        invoice.id, fee_schedule_id=fee_schedule.fee_schedule_id)
    line.save()
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    # Mock here that the invoice update fails here to test the rollback scenario
    with patch(
            'pay_api.services.payment_transaction.PaymentTransaction.find_active_by_payment_id',
            side_effect=Exception('mocked error'),
    ):
        with pytest.raises(Exception) as excinfo:
            PaymentService.update_payment(payment.id, get_payment_request(),
                                          'test')
        assert excinfo.type == Exception

    with patch(
            'pay_api.services.payment_transaction.PaymentTransaction.update_transaction',
            side_effect=Exception('mocked error'),
    ):
        with pytest.raises(Exception) as excinfo:
            PaymentService.update_payment(payment.id, get_payment_request(),
                                          'test')
        assert excinfo.type == Exception

    with patch('pay_api.services.payment.Payment.find_by_id',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.update_payment(payment.id, get_payment_request(),
                                          'test')
        assert excinfo.type == Exception

    with patch('pay_api.services.payment_line_item.PaymentLineItem.create',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.update_payment(payment.id, get_payment_request(),
                                          'test')
        assert excinfo.type == Exception

    # reset transaction
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    with patch('pay_api.services.paybc_service.PaybcService.update_invoice',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.update_payment(payment.id, get_payment_request(),
                                          'test')
        assert excinfo.type == Exception

    # reset transaction
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    with patch('pay_api.services.invoice.Invoice.find_by_id',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.update_payment(payment.id, get_payment_request(),
                                          'test')
        assert excinfo.type == Exception

    # reset transaction
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    with patch('pay_api.services.invoice.Invoice.save',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.update_payment(payment.id, get_payment_request(),
                                          'test')
        assert excinfo.type == Exception

    # reset transaction
    transaction = factory_payment_transaction(payment.id)
    transaction.save()

    with patch('pay_api.services.payment.Payment.save',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.update_payment(payment.id, get_payment_request(),
                                          'test')
        assert excinfo.type == Exception