Exemplo n.º 1
0
def test_get_monthly_statement_report_as_csv(session, client, jwt, app):
    """Assert that the monthly statement report is returning response."""
    # Create a payment account and statement details, then get all statements for the account
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Accept': ContentType.CSV.value
    }

    rv = client.post('/api/v1/payment-requests',
                     data=json.dumps(
                         get_payment_request(business_identifier='CP0002000')),
                     headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    bcol_account: BcolPaymentAccount = BcolPaymentAccount.find_by_id(
        payment.invoices[0].bcol_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        bcol_account.account_id)

    settings_model = factory_statement_settings(
        payment_account_id=pay_account.id,
        frequency=StatementFrequency.DAILY.value)
    statement_model = factory_statement(
        payment_account_id=pay_account.id,
        frequency=StatementFrequency.DAILY.value,
        statement_settings_id=settings_model.id)
    factory_statement_invoices(statement_id=statement_model.id,
                               invoice_id=payment.invoices[0].id)

    rv = client.get(
        f'/api/v1/accounts/{pay_account.auth_account_id}/statements/{statement_model.id}',
        headers=headers)
    assert rv.status_code == 200
Exemplo n.º 2
0
def factory_payment_account(corp_number: str = 'CP0001234',
                            corp_type_code: str = 'CP',
                            payment_system_code: str = 'PAYBC',
                            account_number='4101',
                            bcol_user_id='test',
                            auth_account_id: str = '1234'):
    """Factory."""
    # Create a payment account
    account = PaymentAccount(auth_account_id=auth_account_id).save()

    if payment_system_code == PaymentSystem.BCOL.value:
        return BcolPaymentAccount(bcol_user_id=bcol_user_id,
                                  bcol_account_id='TEST',
                                  account_id=account.id)
    elif payment_system_code == PaymentSystem.PAYBC.value:
        return CreditPaymentAccount(corp_number=corp_number,
                                    corp_type_code=corp_type_code,
                                    paybc_party='11111',
                                    paybc_account=account_number,
                                    paybc_site='29921',
                                    account_id=account.id)
    elif payment_system_code == PaymentSystem.INTERNAL.value:
        return InternalPaymentAccount(corp_number=corp_number,
                                      corp_type_code=corp_type_code,
                                      account_id=account.id)
Exemplo n.º 3
0
def factory_premium_payment_account(bcol_user_id='PB25020',
                                    bcol_account_id='1234567890',
                                    auth_account_id='1234'):
    """Return Factory."""
    account = PaymentAccount(auth_account_id=auth_account_id).save()

    return BcolPaymentAccount(bcol_user_id=bcol_user_id,
                              bcol_account_id=bcol_account_id,
                              account_id=account.id)
Exemplo n.º 4
0
def factory_premium_payment_account(corp_number: str = 'CP0001234',
                                    corp_type_code: str = 'CP',
                                    payment_system_code: str = 'BCOL',
                                    bcol_user_id='PB25020',
                                    bcol_account_id='1234567890',
                                    auth_account_id='1234'):
    """Factory."""
    account = PaymentAccount(auth_account_id=auth_account_id).save()

    return BcolPaymentAccount(bcol_user_id=bcol_user_id,
                              bcol_account_id=bcol_account_id,
                              account_id=account.id)
Exemplo n.º 5
0
def test_get_default_statement_settings_weekly(session, client, jwt, app):
    """Assert that the default statement setting is weekly."""
    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(business_identifier='CP0002000')),
                     headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    bcol_account: BcolPaymentAccount = BcolPaymentAccount.find_by_id(payment.invoices[0].bcol_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(bcol_account.account_id)
    rv = client.get(f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings',
                    headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('frequency') == StatementFrequency.WEEKLY.value
Exemplo n.º 6
0
def test_post_default_statement_settings_daily(session, client, jwt, app):
    """Assert that the post endpoint works."""
    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(business_identifier='CP0002000')),
                     headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    bcol_account: BcolPaymentAccount = BcolPaymentAccount.find_by_id(payment.invoices[0].bcol_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(bcol_account.account_id)

    rv = client.get(f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings', data=json.dumps({}),
                    headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('frequency') == StatementFrequency.WEEKLY.value

    # Set the frequency to Daily and assert
    daily_frequency = {'frequency': 'DAILY'}
    rv = client.post(f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings',
                     data=json.dumps(daily_frequency),
                     headers=headers)
    assert rv.json.get('frequency') == StatementFrequency.DAILY.value
    end_date = get_week_start_and_end_date()[1]
    assert rv.json.get('fromDate') == (end_date + timedelta(days=1)).strftime('%Y-%m-%d')

    # Set the frequency to Monthly and assert
    daily_frequency = {'frequency': 'MONTHLY'}
    rv = client.post(f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings',
                     data=json.dumps(daily_frequency),
                     headers=headers)
    end_date = get_first_and_last_dates_of_month(current_local_time().month, current_local_time().year)[1]
    assert rv.json.get('frequency') == StatementFrequency.MONTHLY.value
    assert rv.json.get('fromDate') == (end_date + timedelta(days=1)).strftime('%Y-%m-%d')

    # Get the latest frequency
    rv = client.get(f'/api/v1/accounts/{pay_account.auth_account_id}/statements/settings', data=json.dumps({}),
                    headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('frequency') == StatementFrequency.MONTHLY.value
Exemplo n.º 7
0
def test_get_weekly_statements(session, client, jwt, app):
    """Assert that the default statement setting is weekly."""
    # Create a payment account and statement details, then get all statements for the account

    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(business_identifier='CP0002000')),
                     headers=headers)

    payment: Payment = Payment.find_by_id(rv.json.get('id'))
    bcol_account: BcolPaymentAccount = BcolPaymentAccount.find_by_id(
        payment.invoices[0].bcol_account_id)
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        bcol_account.account_id)

    settings_model = factory_statement_settings(
        payment_account_id=pay_account.id,
        frequency=StatementFrequency.DAILY.value)
    statement_model = factory_statement(
        payment_account_id=pay_account.id,
        frequency=StatementFrequency.WEEKLY.value,
        statement_settings_id=settings_model.id)
    factory_statement_invoices(statement_id=statement_model.id,
                               invoice_id=payment.invoices[0].id)

    rv = client.get(
        f'/api/v1/accounts/{pay_account.auth_account_id}/statements',
        headers=headers)
    assert rv.status_code == 200
    assert rv.json.get('total') == 1
    assert rv.json.get('items')[0].get(
        'frequency') == StatementFrequency.WEEKLY.value