Esempio n. 1
0
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
Esempio n. 2
0
 def delete(account_number: str):
     """Get payment account details."""
     current_app.logger.info('<Account.delete')
     # Check if user is authorized to perform this action
     check_auth(business_identifier=None,
                account_id=account_number,
                one_of_roles=[EDIT_ROLE, VIEW_ROLE])
     try:
         PaymentAccountService.delete_account(account_number)
     except BusinessException as exception:
         return exception.response()
     except ServiceUnavailableException as exception:
         return exception.response()
     current_app.logger.debug('>Account.delete')
     return jsonify({}), HTTPStatus.NO_CONTENT
Esempio n. 3
0
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