Ejemplo n.º 1
0
def test_create_bcol_payment_for_basic_user(session, public_user_mock):
    """Assert that the payment records are created."""
    with pytest.raises(Exception) as excinfo:
        PaymentService.create_payment(
            get_payment_request_with_payment_method(payment_method='DRAWDOWN', business_identifier='CP0002000'),
            get_auth_basic_user())
    assert excinfo.type == BusinessException
Ejemplo n.º 2
0
def test_create_payment_record(session):
    """Assert that the payment records are created."""
    payment_response = PaymentService.create_payment(get_payment_request(), 'test')
    account_model = PaymentAccount.find_by_corp_number_and_corp_type_and_system('CP1234', 'CP', 'PAYBC')
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None
    # Create another payment with same request, the account should be the same
    PaymentService.create_payment(get_payment_request(), 'test')
    account_model = PaymentAccount.find_by_corp_number_and_corp_type_and_system('CP1234', 'CP', 'PAYBC')
    assert account_id == account_model.id
Ejemplo n.º 3
0
def test_create_payment_record(session, public_user_mock):
    """Assert that the payment records are created."""
    payment_response = PaymentService.create_payment(get_payment_request(), get_auth_basic_user())
    account_model = CreditPaymentAccount. \
        find_by_corp_number_and_corp_type_and_auth_account_id('CP0001234', 'CP',
                                                              get_auth_basic_user().get('account').get('id'))
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None
    # Create another payment with same request, the account should be the same
    PaymentService.create_payment(get_payment_request(), get_auth_basic_user())
    account_model = CreditPaymentAccount. \
        find_by_corp_number_and_corp_type_and_auth_account_id('CP0001234', 'CP',
                                                              get_auth_basic_user().get('account').get('id'))
    assert account_id == account_model.id
Ejemplo n.º 4
0
def test_create_zero_dollar_payment_record(session, public_user_mock):
    """Assert that the payment records are created and completed."""
    payment_response = PaymentService.create_payment(
        get_zero_dollar_payment_request())
    account_model = PaymentAccount.find_by_corp_number_and_corp_type_and_system(
        'CP0001234', 'CP', 'INTERNAL')
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None
    assert payment_response.get('status_code') == 'COMPLETED'
    # Create another payment with same request, the account should be the same
    PaymentService.create_payment(get_zero_dollar_payment_request())
    account_model = PaymentAccount.find_by_corp_number_and_corp_type_and_system(
        'CP0001234', 'CP', 'INTERNAL')
    assert account_id == account_model.id
    assert payment_response.get('status_code') == 'COMPLETED'
Ejemplo n.º 5
0
def test_create_payment_record_with_direct_pay(session, public_user_mock):
    """Assert that the payment records are created."""
    current_app.config['DIRECT_PAY_ENABLED'] = True
    payment_response = PaymentService.create_payment(
        get_payment_request(), get_auth_basic_user(PaymentMethod.DIRECT_PAY.value))
    account_model = CreditPaymentAccount. \
        find_by_corp_number_and_corp_type_and_auth_account_id('CP0001234', 'CP',
                                                              get_auth_basic_user().get('account').get('id'))
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None
    # Create another payment with same request, the account should be the same
    PaymentService.create_payment(get_payment_request(), get_auth_basic_user())
    account_model = CreditPaymentAccount. \
        find_by_corp_number_and_corp_type_and_auth_account_id('CP0001234', 'CP',
                                                              get_auth_basic_user().get('account').get('id'))
    assert account_id == account_model.id
Ejemplo n.º 6
0
def test_create_bcol_payment(session, public_user_mock):
    """Assert that the payment records are created."""
    payment_response = PaymentService.create_payment(
        get_payment_request_with_payment_method(payment_method='DRAWDOWN', business_identifier='CP0002000'),
        get_auth_premium_user())
    assert payment_response is not None
    assert payment_response.get('payment_system') == 'BCOL'
    assert payment_response.get('status_code') == 'COMPLETED'
Ejemplo n.º 7
0
def test_create_payment_record_with_service_charge(session, public_user_mock):
    """Assert that the payment records are created."""
    # Create a payment request for corp type BC
    payment_response = PaymentService.create_payment(get_payment_request(corp_type='BC'), get_auth_basic_user())
    account_model = CreditPaymentAccount. \
        find_by_corp_number_and_corp_type_and_auth_account_id('CP0001234', 'BC',
                                                              get_auth_basic_user().get('account').get('id'))
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None
    assert payment_response.get('invoices')[0].get('service_fees') == 1.50
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
0
def test_create_payment_record(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'
            }]
        }
    }
    payment_response = PaymentService.create_payment(payment_request, 'test')
    account_model = PaymentAccountModel.find_by_corp_number_and_corp_type_and_system(
        'CP1234', 'CP', 'PAYBC')
    account_id = account_model.id
    assert account_id is not None
    assert payment_response.get('id') is not None
    # Create another payment with same request, the account should be the same
    PaymentService.create_payment(payment_request, 'test')
    account_model = PaymentAccountModel.find_by_corp_number_and_corp_type_and_system(
        'CP1234', 'CP', 'PAYBC')
    assert account_id == account_model.id
Ejemplo n.º 11
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
Ejemplo n.º 12
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