Esempio n. 1
0
def test_create_receipt_without_invoice(session):
    """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()
    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(), 'test')
    input_data = {
        'corpName': 'Pennsular Coop ',
        'filingDateTime': '1999',
        'fileName': 'coopser'
    }
    response = ReceiptService.create_receipt(payment.id, '', input_data, None)
    assert response is not None
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
0
def test_create_payment_record_rollback(session):
    """Assert that the payment records are created."""
    # Mock here that the invoice update fails here to test the rollback scenario
    with patch('pay_api.services.invoice.Invoice.save', side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == Exception

    with patch('pay_api.services.payment.Payment.create', side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == Exception
    with patch('pay_api.services.paybc_service.PaybcService.create_invoice', side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == Exception
Esempio n. 5
0
def test_create_payment_record_rollback(session):
    """Assert that the payment records are created."""
    payment_request = {
        'payment_info': {
            'method_of_payment': 'CC'
        },
        'business_info': {
            'business_identifier': 'CP1234',
            'corp_type': 'CP',
            'business_name': 'ABC Corp',
            'contact_info': {
                'city': 'Victoria',
                'postal_code': 'V8P2P2',
                'province': 'BC',
                'address_line_1': '100 Douglas Street',
                'country': 'CA'
            }
        },
        'filing_info': {
            'filing_types': [{
                'filing_type_code': 'OTADD',
                'filing_description': 'TEST'
            }, {
                'filing_type_code': 'OTANN'
            }]
        }
    }

    # Mock here that the invoice update fails here to test the rollback scenario
    with patch('pay_api.services.invoice.Invoice.save',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_payment(payment_request, 'test')
        assert excinfo.type == Exception

    with patch('pay_api.services.payment.Payment.create',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_payment(payment_request, 'test')
        assert excinfo.type == Exception
    with patch('pay_api.services.paybc_service.PaybcService.create_invoice',
               side_effect=Exception('mocked error')):
        with pytest.raises(Exception) as excinfo:
            PaymentService.create_payment(payment_request, 'test')
        assert excinfo.type == Exception
Esempio n. 6
0
def test_create_payment_record_rollback_on_paybc_connection_error(session, public_user_mock):
    """Assert that the payment records are not created."""
    # Mock here that the invoice update fails here to test the rollback scenario
    with patch('pay_api.services.oauth_service.requests.post', side_effect=ConnectionError('mocked error')):
        with pytest.raises(ServiceUnavailableException) as excinfo:
            PaymentService.create_payment(get_payment_request(), get_auth_basic_user())
        assert excinfo.type == ServiceUnavailableException

    with patch('pay_api.services.oauth_service.requests.post', side_effect=ConnectTimeout('mocked error')):
        with pytest.raises(ServiceUnavailableException) as excinfo:
            PaymentService.create_payment(get_payment_request(), get_auth_basic_user())
        assert excinfo.type == ServiceUnavailableException

    with patch('pay_api.services.oauth_service.requests.post', side_effect=HTTPError('mocked error')) as post_mock:
        post_mock.status_Code = 503
        with pytest.raises(HTTPError) as excinfo:
            PaymentService.create_payment(get_payment_request(), get_auth_basic_user())
        assert excinfo.type == HTTPError
Esempio n. 7
0
def test_create_payment_record_rollback_on_paybc_connection_error(session):
    """Assert that the payment records are not created."""
    from unittest.mock import Mock
    # Mock here that the invoice update fails here to test the rollback scenario
    with patch('pay_api.services.oauth_service.requests.post', side_effect=ConnectionError('mocked error')):
        with pytest.raises(ServiceUnavailableException) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == ServiceUnavailableException
    with patch('pay_api.services.oauth_service.requests.post', side_effect=ConnectTimeout('mocked error')):
        with pytest.raises(ServiceUnavailableException) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == ServiceUnavailableException

    mock_create_site = patch('pay_api.services.oauth_service.requests.post')

    mock_post = mock_create_site.start()
    mock_post.return_value = Mock(status_code=503)

    with patch('pay_api.services.oauth_service.requests.post', side_effect=HTTPError('mocked error')) as post_mock:
        post_mock.status_Code = 503
        with pytest.raises(HTTPError) as excinfo:
            PaymentService.create_payment(get_payment_request(), 'test')
        assert excinfo.type == HTTPError
Esempio n. 8
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