def test_create_pad_account_but_drawdown_is_active(session): """Assert updating PAD to DRAWDOWN works.""" # Create a PAD Account first pad_account = PaymentAccountService.create(get_pad_account_payload()) # Update this payment account with drawdown and assert payment method assert pad_account.payment_method == PaymentMethod.DRAWDOWN.value assert pad_account.cfs_account_id
def test_premium_account_update_bcol_pad(session, client, jwt, app): """Assert that the endpoint returns 200.""" token = jwt.create_jwt(get_claims(roles=[Role.SYSTEM.value]), token_header) headers = {'Authorization': f'Bearer {token}', 'content-type': 'application/json'} rv = client.post('/api/v1/accounts', data=json.dumps(get_premium_account_payload()), headers=headers) auth_account_id = rv.json.get('authAccountId') rv = client.get(f'/api/v1/accounts/{auth_account_id}', headers=headers) assert rv.json.get('authAccountId') == auth_account_id # assert switching to PAD returns bank details pad_account_details = get_pad_account_payload(account_id=int(auth_account_id)) rv = client.put(f'/api/v1/accounts/{auth_account_id}', data=json.dumps(pad_account_details), headers=headers) assert rv.status_code == 202 assert rv.json.get('futurePaymentMethod') == PaymentMethod.PAD.value assert rv.json.get('bankTransitNumber') == pad_account_details.get('bankTransitNumber') # Assert switching to bcol returns no bank details rv = client.put(f'/api/v1/accounts/{auth_account_id}', data=json.dumps(get_premium_account_payload()), headers=headers) assert rv.json.get('futurePaymentMethod') is None assert rv.json.get('bankTransitNumber') is None
def test_delete_account_failures(session): """Assert that delete payment account works.""" # Create a PAD Account. # Add credit and assert account cannot be deleted. # Remove the credit. # Add a PAD transaction for within N days and mark as PAID. # Assert account cannot be deleted. # Mark the account as NSF and assert account cannot be deleted. payload = get_pad_account_payload() pay_account: PaymentAccountService = PaymentAccountService.create(payload) pay_account.credit = 100 pay_account.save() with pytest.raises(BusinessException) as excinfo: PaymentAccountService.delete_account(payload.get('accountId')) assert excinfo.value.code == Error.OUTSTANDING_CREDIT.code # Now mark the credit as zero and mark teh CFS account status as FREEZE. pay_account.credit = 0 pay_account.save() cfs_account = CfsAccountModel.find_effective_by_account_id(pay_account.id) cfs_account.status = CfsAccountStatus.FREEZE.value cfs_account.save() with pytest.raises(BusinessException) as excinfo: PaymentAccountService.delete_account(payload.get('accountId')) assert excinfo.value.code == Error.FROZEN_ACCOUNT.code # Now mark the status ACTIVE and create transactions within configured time. cfs_account = CfsAccountModel.find_effective_by_account_id(pay_account.id) cfs_account.status = CfsAccountStatus.ACTIVE.value cfs_account.save() created_on: datetime = get_outstanding_txns_from_date() + timedelta( minutes=1) factory_invoice(pay_account, payment_method_code=PaymentMethod.PAD.value, created_on=created_on, status_code=InvoiceStatus.PAID.value).save() with pytest.raises(BusinessException) as excinfo: PaymentAccountService.delete_account(payload.get('accountId')) assert excinfo.value.code == Error.TRANSACTIONS_IN_PROGRESS.code
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 def test_delete_account_failures(session): """Assert that delete payment account works."""