Ejemplo n.º 1
0
def test_update_statement_daily_to_daily(session):
    """Assert that going from daily to daily creates a new record."""
    bcol_account = factory_premium_payment_account()
    bcol_account.save()

    payment = factory_payment()
    payment.save()
    i = factory_invoice(payment_account=bcol_account)
    i.save()
    factory_invoice_reference(i.id).save()
    factory_statement_settings(payment_account_id=bcol_account.id,
                               frequency=StatementFrequency.DAILY.value)

    # update to weekly
    payment_account = PaymentAccount.find_by_id(bcol_account.id)
    statement_settings = StatementSettingsService.update_statement_settings(payment_account.auth_account_id,
                                                                            StatementFrequency.DAILY.value)
    assert statement_settings is not None
    assert statement_settings.get('frequency') == StatementFrequency.DAILY.value
    assert statement_settings.get('to_date') is None

    # daily to daily - assert daily should start by tomorow
    assert statement_settings.get('from_date') == (datetime.today() + timedelta(days=1)).strftime('%Y-%m-%d')

    # daily to daily - assert current active one is stil daily ending today
    current_statement_settings = StatementSettingsModel.find_active_settings(payment_account.auth_account_id,
                                                                             datetime.today())
    assert current_statement_settings is not None
    assert current_statement_settings.frequency == StatementFrequency.DAILY.value
    assert current_statement_settings.to_date == datetime.today().date()
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def test_get_statement_report_for_empty_invoices(session):
    """Assert that the get statement report works for statement with no invoices."""
    bcol_account = factory_premium_payment_account()
    bcol_account.save()

    payment = factory_payment()
    payment.save()
    i = factory_invoice(payment_account=bcol_account)
    i.save()
    factory_invoice_reference(i.id).save()
    factory_payment_line_item(invoice_id=i.id, fee_schedule_id=1).save()

    settings_model = factory_statement_settings(
        payment_account_id=bcol_account.id,
        frequency=StatementFrequency.DAILY.value)
    statement_model = factory_statement(
        payment_account_id=bcol_account.id,
        frequency=StatementFrequency.DAILY.value,
        statement_settings_id=settings_model.id)

    payment_account = PaymentAccount.find_by_id(bcol_account.id)
    statements = StatementService.find_by_account_id(
        payment_account.auth_account_id, page=1, limit=10)
    assert statements is not None

    report_response, report_name = StatementService.get_statement_report(
        statement_id=statement_model.id,
        content_type='application/pdf',
        auth=get_auth_premium_user())
    assert report_response is not None
Ejemplo n.º 4
0
def test_statement_find_by_account(session):
    """Assert that the statement settings by id works."""
    bcol_account = factory_premium_payment_account()
    bcol_account.save()

    payment = factory_payment()
    payment.save()
    i = factory_invoice(payment_account=bcol_account)
    i.save()
    factory_invoice_reference(i.id).save()

    settings_model = factory_statement_settings(
        payment_account_id=bcol_account.id,
        frequency=StatementFrequency.DAILY.value)
    statement_model = factory_statement(
        payment_account_id=bcol_account.id,
        frequency=StatementFrequency.DAILY.value,
        statement_settings_id=settings_model.id)
    factory_statement_invoices(statement_id=statement_model.id,
                               invoice_id=i.id)

    payment_account = PaymentAccount.find_by_id(bcol_account.id)
    statements = StatementService.find_by_account_id(
        payment_account.auth_account_id, page=1, limit=10)
    assert statements is not None
    assert statements.get('total') == 1
Ejemplo n.º 5
0
def test_statement_settings_find_by_account(session):
    """Assert that the statement settings by id works."""
    bcol_account = factory_premium_payment_account()
    bcol_account.save()

    payment = factory_payment()
    payment.save()
    i = factory_invoice(payment_account=bcol_account)
    i.save()
    factory_invoice_reference(i.id).save()
    factory_statement_settings(payment_account_id=bcol_account.id,
                               frequency=StatementFrequency.DAILY.value)

    payment_account = PaymentAccount.find_by_id(bcol_account.id)
    statement_settings = StatementSettingsService.find_by_account_id(payment_account.auth_account_id)
    assert statement_settings is not None
    assert statement_settings.get('current_frequency').get('frequency') == StatementFrequency.DAILY.value
Ejemplo n.º 6
0
def test_update_statement_monthly(session):
    """Assert that the statement settings by id works."""
    bcol_account = factory_premium_payment_account()
    bcol_account.save()

    payment = factory_payment()
    payment.save()
    i = factory_invoice(payment_account=bcol_account)
    i.save()
    factory_invoice_reference(i.id).save()
    factory_statement_settings(payment_account_id=bcol_account.id,
                               frequency=StatementFrequency.MONTHLY.value)

    # update to weekly
    payment_account = PaymentAccount.find_by_id(bcol_account.id)
    statement_settings = StatementSettingsService.update_statement_settings(
        payment_account.auth_account_id, StatementFrequency.WEEKLY.value)
    assert statement_settings is not None
    assert statement_settings.get(
        'frequency') == StatementFrequency.WEEKLY.value
    assert statement_settings.get('to_date') is None

    # monthly to weekly - assert weekly should start by next week first day
    end_of_month_date = get_first_and_last_dates_of_month(
        datetime.today().month,
        datetime.today().year)[1]
    assert statement_settings.get('from_date') == (
        end_of_month_date + timedelta(days=1)).strftime(DT_SHORT_FORMAT)

    # monthly to weekly - assert current active one is stil monthly ending end of the week
    current_statement_settings = StatementSettingsModel.find_active_settings(
        payment_account.auth_account_id, datetime.today())
    assert current_statement_settings is not None
    assert current_statement_settings.frequency == StatementFrequency.MONTHLY.value
    assert current_statement_settings.to_date == end_of_month_date.date()

    # travel to next week and see whats active
    with freeze_time(end_of_month_date + timedelta(days=2)):
        next_week_statement_settings = StatementSettingsModel.find_active_settings(
            payment_account.auth_account_id, datetime.today())
        assert next_week_statement_settings is not None
        assert next_week_statement_settings.frequency == StatementFrequency.WEEKLY.value
        assert next_week_statement_settings.to_date is None
Ejemplo n.º 7
0
def test_get_daily_statements_verify_order(session, client, jwt, app):
    """Assert that the default statement setting is daily."""
    # 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)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_account_id)

    settings_model = factory_statement_settings(
        payment_account_id=pay_account.id,
        frequency=StatementFrequency.DAILY.value)
    factory_statement(payment_account_id=pay_account.id,
                      frequency=StatementFrequency.DAILY.value,
                      statement_settings_id=settings_model.id)
    factory_statement(payment_account_id=pay_account.id,
                      frequency=StatementFrequency.WEEKLY.value,
                      statement_settings_id=settings_model.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') == 2
    # should come in the order latest first
    assert rv.json.get('items')[0].get(
        'frequency') == StatementFrequency.WEEKLY.value
    assert rv.json.get('items')[1].get(
        'frequency') == StatementFrequency.DAILY.value