Пример #1
0
def test_update_online_banking_account_when_cfs_down(session, client, jwt,
                                                     app):
    """Assert that the payment records are created with 200, as there is no CFS update."""
    token = jwt.create_jwt(get_claims(role=Role.SYSTEM.value), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    rv = client.post(
        '/api/v1/accounts',
        data=json.dumps(
            get_basic_account_payload(
                payment_method=PaymentMethod.ONLINE_BANKING.value)),
        headers=headers)
    auth_account_id = rv.json.get('accountId')
    # Mock ServiceUnavailableException
    with patch('pay_api.services.oauth_service.OAuthService.post',
               side_effect=ServiceUnavailableException(
                   ConnectionError('mocked error'))):
        rv = client.put(
            f'/api/v1/accounts/{auth_account_id}',
            data=json.dumps(
                get_basic_account_payload(
                    payment_method=PaymentMethod.ONLINE_BANKING.value)),
            headers=headers)

        assert rv.status_code == 202
Пример #2
0
def test_update_online_banking_to_credit(session):
    """Assert that update from online banking to credit card works."""
    online_banking_account = PaymentAccountService.create(
        get_basic_account_payload(
            payment_method=PaymentMethod.ONLINE_BANKING.value))
    credit_account = PaymentAccountService.update(
        online_banking_account.auth_account_id, get_basic_account_payload())
    assert credit_account.payment_method == PaymentMethod.DIRECT_PAY.value
Пример #3
0
def test_update_credit_to_online_banking(session):
    """Assert that update from credit card to online banking works."""
    credit_account = PaymentAccountService.create(get_basic_account_payload())
    online_banking_account = PaymentAccountService.update(
        credit_account.auth_account_id,
        get_basic_account_payload(
            payment_method=PaymentMethod.ONLINE_BANKING.value))
    assert online_banking_account.payment_method == PaymentMethod.ONLINE_BANKING.value
    assert online_banking_account.cfs_account_id
    assert online_banking_account.cfs_account is None
    assert online_banking_account.cfs_party is None
    assert online_banking_account.cfs_site is None
    assert online_banking_account.bank_number is None
Пример #4
0
def test_update_online_banking_account_when_cfs_up(session, client, jwt, app):
    """Assert that the payment records are created with 200."""
    token = jwt.create_jwt(get_claims(role=Role.SYSTEM.value), token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}
    rv = client.post('/api/v1/accounts',
                     data=json.dumps(get_basic_account_payload(payment_method=PaymentMethod.ONLINE_BANKING.value)),
                     headers=headers)
    auth_account_id = rv.json.get('authAccountId')
    rv = client.put(f'/api/v1/accounts/{auth_account_id}',
                    data=json.dumps(get_basic_account_payload(payment_method=PaymentMethod.ONLINE_BANKING.value)),
                    headers=headers)

    assert rv.status_code == 202
Пример #5
0
def test_payment_creation_when_paybc_down(session, client, jwt, app):
    """Assert that the endpoint returns 400."""
    token = jwt.create_jwt(get_claims(role=Role.SYSTEM.value), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Account-Id': '1234'
    }

    # Create an account first with CC as preffered payment, and it will create a DIRECT_PAY account
    client.post('/api/v1/accounts',
                data=json.dumps(
                    get_basic_account_payload(PaymentMethod.CC.value)),
                headers=headers)

    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(get_payment_request()),
                     headers=headers)
    assert rv.status_code == 201
    assert rv.json.get('isPaymentActionRequired')
Пример #6
0
def test_basic_account_creation_unauthorized(session, client, jwt, app):
    """Assert that the endpoint returns 401."""
    token = jwt.create_jwt(get_claims(role=Role.EDITOR.value), token_header)
    headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'}

    rv = client.post('/api/v1/accounts', data=json.dumps(get_basic_account_payload()),
                     headers=headers)

    assert rv.status_code == 401
Пример #7
0
def test_create_online_banking_account(session):
    """Assert that create online banking account works."""
    online_banking_account = PaymentAccountService.create(
        get_basic_account_payload(payment_method=PaymentMethod.ONLINE_BANKING.value))
    assert online_banking_account.payment_method == PaymentMethod.ONLINE_BANKING.value
    assert online_banking_account.cfs_account_id
    assert online_banking_account.cfs_account is None
    assert online_banking_account.cfs_party is None
    assert online_banking_account.cfs_site is None
    assert online_banking_account.bank_number is None
Пример #8
0
def test_payment_request_online_banking_with_credit(session, client, jwt, app):
    """Assert that the endpoint returns 201."""
    token = jwt.create_jwt(get_claims(role=Role.SYSTEM.value), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    rv = client.post(
        '/api/v1/accounts',
        data=json.dumps(
            get_basic_account_payload(
                payment_method=PaymentMethod.ONLINE_BANKING.value)),
        headers=headers)
    auth_account_id = rv.json.get('authAccountId')

    # Update the payment account as ACTIVE
    payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
        auth_account_id)
    payment_account.credit = 51
    payment_account.save()

    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request_with_payment_method(
                             business_identifier='CP0002000',
                             payment_method='ONLINE_BANKING')),
                     headers=headers)
    invoice_id = rv.json.get('id')

    rv = client.patch(
        f'/api/v1/payment-requests/{invoice_id}?applyCredit=true',
        data=json.dumps({}),
        headers=headers)

    payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
        auth_account_id)
    assert payment_account.credit == 1

    # Now set the credit less than the total of invoice.
    payment_account.credit = 49
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request_with_payment_method(
                             business_identifier='CP0002000',
                             payment_method='ONLINE_BANKING')),
                     headers=headers)
    invoice_id = rv.json.get('id')

    rv = client.patch(
        f'/api/v1/payment-requests/{invoice_id}?applyCredit=true',
        data=json.dumps({}),
        headers=headers)
    # Credit won't be applied as the invoice total is 50 and the credit should remain as 0.
    payment_account: PaymentAccountModel = PaymentAccountModel.find_by_auth_account_id(
        auth_account_id)
    assert payment_account.credit == 0
Пример #9
0
def test_create_online_credit_account(session):
    """Assert that create credit card account works."""
    credit_account = PaymentAccountService.create(get_basic_account_payload())
    assert credit_account.payment_method == PaymentMethod.DIRECT_PAY.value
    assert credit_account.cfs_account_id is None
Пример #10
0
    assert online_banking_account.cfs_site is None
    assert online_banking_account.bank_number is None


def test_update_online_banking_to_credit(session):
    """Assert that update from online banking to credit card works."""
    online_banking_account = PaymentAccountService.create(
        get_basic_account_payload(
            payment_method=PaymentMethod.ONLINE_BANKING.value))
    credit_account = PaymentAccountService.update(
        online_banking_account.auth_account_id, get_basic_account_payload())
    assert credit_account.payment_method == PaymentMethod.DIRECT_PAY.value


@pytest.mark.parametrize('payload', [
    get_basic_account_payload(
        payment_method=PaymentMethod.ONLINE_BANKING.value),
    get_basic_account_payload(),
    get_premium_account_payload(),
    get_pad_account_payload(),
    get_unlinked_pad_account_payload()
])
def test_delete_account(session, payload):
    """Assert that delete payment account works."""
    pay_account: PaymentAccountService = PaymentAccountService.create(payload)
    PaymentAccountService.delete_account(payload.get('accountId'))

    # Try to find the account by id.
    pay_account = PaymentAccountService.find_by_id(pay_account.id)
    for cfs_account in CfsAccountModel.find_by_account_id(pay_account.id):
        assert cfs_account.status == CfsAccountStatus.INACTIVE.value if cfs_account else True