def test_activate_bcol_change_to_pad(session):
    """Test Activate account."""
    # Create a pending account first, then call the job
    account = factory_create_pad_account(
        auth_account_id='1', payment_method=PaymentMethod.DRAWDOWN.value)
    CreateAccountTask.create_accounts()
    account = PaymentAccount.find_by_id(account.id)
    cfs_account: CfsAccount = CfsAccount.find_effective_by_account_id(
        account.id)
    assert cfs_account.status == CfsAccountStatus.PENDING_PAD_ACTIVATION.value, 'Created account has pending pad status'
    assert account.payment_method == PaymentMethod.DRAWDOWN.value

    ActivatePadAccountTask.activate_pad_accounts()
    cfs_account: CfsAccount = CfsAccount.find_effective_by_account_id(
        account.id)
    assert cfs_account.status == CfsAccountStatus.PENDING_PAD_ACTIVATION.value, \
        'Same day Job runs and shouldnt change anything.'
    account = PaymentAccount.find_by_id(account.id)
    assert account.payment_method == PaymentMethod.DRAWDOWN.value

    time_delay = current_app.config['PAD_CONFIRMATION_PERIOD_IN_DAYS']
    with freeze_time(datetime.today() + timedelta(days=time_delay, minutes=1)):
        ActivatePadAccountTask.activate_pad_accounts()
        assert cfs_account.status == CfsAccountStatus.ACTIVE.value, \
            'After the confirmation period is over , status should be active'
        account = PaymentAccount.find_by_id(account.id)
        assert account.payment_method == PaymentMethod.PAD.value
def test_update_pad_account(session):
    """Test update account."""
    # Create a pending account first, then call the job
    account = factory_create_pad_account(auth_account_id='2')
    CreateAccountTask.create_accounts()

    account = PaymentAccount.find_by_id(account.id)
    cfs_account = CfsAccount.find_effective_by_account_id(account.id)

    assert cfs_account.payment_instrument_number

    # Now update the account.
    new_payment_details = {
        'bankInstitutionNumber': '111',
        'bankTransitNumber': '222',
        'bankAccountNumber': '3333333333'
    }
    PadService().update_account(name='Test', cfs_account=cfs_account, payment_info=new_payment_details)
    cfs_account = CfsAccount.find_by_id(cfs_account.id)

    # Run the job again
    CreateAccountTask.create_accounts()

    updated_cfs_account: CfsAccount = CfsAccount.find_effective_by_account_id(account.id)
    assert updated_cfs_account.id != cfs_account.id
    assert updated_cfs_account.bank_account_number == new_payment_details.get('bankAccountNumber')
    assert updated_cfs_account.bank_branch_number == new_payment_details.get('bankTransitNumber')
    assert updated_cfs_account.bank_number == new_payment_details.get('bankInstitutionNumber')

    assert cfs_account.status == CfsAccountStatus.INACTIVE.value
    assert updated_cfs_account.status == CfsAccountStatus.PENDING_PAD_ACTIVATION.value
    assert updated_cfs_account.payment_instrument_number
예제 #3
0
def test_create_rs_account(session):
    """Test create account."""
    # Create a pending account first, then call the job
    account = factory_routing_slip_account()
    CreateAccountTask.create_accounts()
    cfs_account: CfsAccount = CfsAccount.find_effective_by_account_id(account.id)
    assert cfs_account.status == CfsAccountStatus.ACTIVE.value
    assert cfs_account.cfs_party
    assert cfs_account.cfs_site
    assert cfs_account.cfs_account
예제 #4
0
def test_create_online_banking_account(session):
    """Test create account."""
    # Create a pending account first, then call the job
    account = factory_create_online_banking_account(auth_account_id='2')
    CreateAccountTask.create_accounts()
    account = PaymentAccount.find_by_id(account.id)
    cfs_account = CfsAccount.find_effective_by_account_id(account.id)
    assert cfs_account.status == CfsAccountStatus.ACTIVE.value
    assert not cfs_account.bank_account_number
    assert cfs_account.cfs_party
    assert cfs_account.cfs_site
    assert cfs_account.cfs_account
    assert cfs_account.payment_instrument_number is None
def test_create_pad_account_no_confirmation_period(session):
    """Test create account.Arbitrary scenario when there is no confirmation period."""
    # Create a pending account first, then call the job
    account = factory_create_pad_account(auth_account_id='1', confirmation_period=0)
    CreateAccountTask.create_accounts()
    account = PaymentAccount.find_by_id(account.id)
    cfs_account: CfsAccount = CfsAccount.find_effective_by_account_id(account.id)
    assert cfs_account.status == CfsAccountStatus.ACTIVE.value
    assert cfs_account.bank_account_number
    assert cfs_account.cfs_party
    assert cfs_account.cfs_site
    assert cfs_account.cfs_account
    assert cfs_account.payment_instrument_number
def test_create_pad_account(session):
    """Test create account."""
    # Create a pending account first, then call the job
    account = factory_create_pad_account(auth_account_id='1')
    CreateAccountTask.create_accounts()
    account = PaymentAccount.find_by_id(account.id)
    cfs_account: CfsAccount = CfsAccount.find_effective_by_account_id(account.id)
    assert cfs_account.status == CfsAccountStatus.PENDING_PAD_ACTIVATION.value
    assert cfs_account.bank_account_number
    assert cfs_account.cfs_party
    assert cfs_account.cfs_site
    assert cfs_account.cfs_account
    assert cfs_account.payment_instrument_number
def test_update_online_banking_account(session):
    """Test update account."""
    # Create a pending account first, then call the job
    account = factory_create_online_banking_account(auth_account_id='2')
    CreateAccountTask.create_accounts()
    account = PaymentAccount.find_by_id(account.id)
    cfs_account = CfsAccount.find_effective_by_account_id(account.id)

    # Update account, which shouldn't change any details
    OnlineBankingService().update_account(name='Test', cfs_account=cfs_account, payment_info=None)
    updated_cfs_account = CfsAccount.find_effective_by_account_id(account.id)

    assert updated_cfs_account.status == CfsAccountStatus.ACTIVE.value
    assert cfs_account.id == updated_cfs_account.id
예제 #8
0
def run(job_name):
    from tasks.cfs_create_account_task import CreateAccountTask
    from tasks.cfs_create_invoice_task import CreateInvoiceTask
    from tasks.distribution_task import DistributionTask
    from tasks.stale_payment_task import StalePaymentTask
    from tasks.statement_notification_task import StatementNotificationTask
    from tasks.statement_task import StatementTask
    from tasks.activate_pad_account_task import ActivatePadAccountTask
    from tasks.ejv_partner_distribution_task import EjvPartnerDistributionTask
    from tasks.unpaid_invoice_notify_task import UnpaidInvoiceNotifyTask
    from tasks.ejv_payment_task import EjvPaymentTask

    application = create_app()

    application.app_context().push()
    if job_name == 'UPDATE_GL_CODE':
        DistributionTask.update_failed_distributions()
        application.logger.info(f'<<<< Completed Updating GL Codes >>>>')
    elif job_name == 'GENERATE_STATEMENTS':
        StatementTask.generate_statements()
        application.logger.info(f'<<<< Completed Generating Statements >>>>')
    elif job_name == 'SEND_NOTIFICATIONS':
        StatementNotificationTask.send_notifications()
        application.logger.info(f'<<<< Completed Sending notifications >>>>')
    elif job_name == 'UPDATE_STALE_PAYMENTS':
        StalePaymentTask.update_stale_payments()
        application.logger.info(f'<<<< Completed Updating stale payments >>>>')
    elif job_name == 'CREATE_CFS_ACCOUNTS':
        CreateAccountTask.create_accounts()
        application.logger.info(f'<<<< Completed creating cfs accounts >>>>')
    elif job_name == 'CREATE_INVOICES':
        CreateInvoiceTask.create_invoices()
        application.logger.info(f'<<<< Completed creating cfs invoices >>>>')
    elif job_name == 'ACTIVATE_PAD_ACCOUNTS':
        ActivatePadAccountTask.activate_pad_accounts()
        application.logger.info(f'<<<< Completed Activating PAD accounts >>>>')
    elif job_name == 'EJV_PARTNER':
        EjvPartnerDistributionTask.create_ejv_file()
        application.logger.info(f'<<<< Completed Creating EJV File for partner distribution>>>>')
    elif job_name == 'NOTIFY_UNPAID_INVOICE_OB':
        UnpaidInvoiceNotifyTask.notify_unpaid_invoices()
        application.logger.info(f'<<<< Completed Sending notification for OB invoices >>>>')
    elif job_name == 'EJV_PAYMENT':
        EjvPaymentTask.create_ejv_file()
        application.logger.info(f'<<<< Completed running EJV payment >>>>')

    else:
        application.logger.debug('No valid args passed.Exiting job without running any ***************')
예제 #9
0
def test_create_pad_account_system_error(session):
    """Test create account."""
    # Create a pending account first, then call the job
    account = factory_create_pad_account(auth_account_id='1')
    cfs_account: CfsAccount = CfsAccount.find_effective_by_account_id(
        account.id)
    assert cfs_account.status == CfsAccountStatus.PENDING.value
    mock_response = requests.models.Response()
    mock_response.headers['CAS-Returned-Messages'] = '[CFS Down]'
    mock_response.status_code = 404

    side_effect = HTTPError(response=mock_response)
    with patch.object(mailer, 'publish_mailer_events') as mock_mailer:
        with patch('pay_api.services.CFSService.create_cfs_account',
                   side_effect=side_effect):
            CreateAccountTask.create_accounts()
            mock_mailer.assert_not_called()

    account = PaymentAccount.find_by_id(account.id)
    cfs_account: CfsAccount = CfsAccount.find_by_id(cfs_account.id)
    assert cfs_account.status == CfsAccountStatus.PENDING.value
예제 #10
0
def test_create_account_setup(session):
    """Test create account."""
    CreateAccountTask.create_accounts()
    assert True