Beispiel #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)

    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)
    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=invoice.id)

    rv = client.get(
        f'/api/v1/accounts/{pay_account.auth_account_id}/statements/{statement_model.id}',
        headers=headers)
    assert rv.status_code == 200
Beispiel #2
0
def test_account_purchase_history_pagination(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    for i in range(10):
        rv = client.post('/api/v1/payment-requests',
                         data=json.dumps(get_payment_request()),
                         headers=headers)

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

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries?page=1&limit=5',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 200
    assert rv.json.get('total') == 10
    assert len(rv.json.get('items')) == 5
Beispiel #3
0
def test_account_purchase_history_default_list(session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    token = jwt.create_jwt(get_claims(), token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }

    # Create 11 payments
    for i in range(11):
        rv = client.post('/api/v1/payment-requests',
                         data=json.dumps(get_payment_request()),
                         headers=headers)

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

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 200
    # Assert the total is coming as 10 which is the value of default TRANSACTION_REPORT_DEFAULT_TOTAL
    assert rv.json.get('total') == 10
Beispiel #4
0
def test_account_purchase_history_export_invalid_request(
        session, client, jwt, app):
    """Assert that the endpoint returns 200."""
    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()),
                     headers=headers)

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

    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json',
        'Accept': 'application/pdf'
    }

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/reports',
        data=json.dumps({'businessIdentifier': 1111}),
        headers=headers)

    assert rv.status_code == 400
Beispiel #5
0
def test_account_purchase_history_invalid_request(session, client, jwt, app):
    """Assert that the endpoint returns 400."""
    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()),
                     headers=headers)

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

    search_filter = {'businessIdentifier': 1111}

    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries?page=1&limit=5',
        data=json.dumps(search_filter),
        headers=headers)

    assert rv.status_code == 400
    assert schema_utils.validate(rv.json, 'problem')[0]
Beispiel #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)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_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('currentFrequency').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('currentFrequency').get(
        'frequency') == StatementFrequency.MONTHLY.value
Beispiel #7
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)

    invoice: Invoice = Invoice.find_by_id(rv.json.get('id'))
    pay_account: PaymentAccount = PaymentAccount.find_by_id(
        invoice.payment_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('currentFrequency').get(
        'frequency') == StatementFrequency.WEEKLY.value
    # Assert the array of the frequncies
    for freqeuncy in rv.json.get('frequencies'):
        if freqeuncy.get('frequency') == StatementFrequency.WEEKLY.value:
            actual_weekly = dateutil.parser.parse(
                freqeuncy.get('startDate')).date()
            expected_weekly = (get_week_start_and_end_date()[1] +
                               timedelta(days=1)).date()
            assert actual_weekly == expected_weekly, 'weekly matches'
        if freqeuncy.get('frequency') == StatementFrequency.MONTHLY.value:
            today = datetime.today()
            actual_monthly = dateutil.parser.parse(
                freqeuncy.get('startDate')).date()
            expected_monthly = (
                get_first_and_last_dates_of_month(today.month, today.year)[1] +
                timedelta(days=1)).date()
            assert actual_monthly == expected_monthly, 'monthly matches'
        if freqeuncy.get('frequency') == StatementFrequency.DAILY.value:
            actual_daily = dateutil.parser.parse(
                freqeuncy.get('startDate')).date()
            # since current frequncy is weekly , daily changes will happen at the end of the week
            expected_weekly = (get_week_start_and_end_date()[1] +
                               timedelta(days=1)).date()
            assert actual_daily == expected_weekly, 'daily matches'
Beispiel #8
0
def test_account_purchase_history_with_service_account(session, client, jwt,
                                                       app):
    """Assert that purchase history returns only invoices for that product."""
    # Create one invoice for CSO and one fpr BUSINESS.
    # Then query without any filter and make sure only CSO invoice is returned for service account with CSO product_code
    for corp_filing_type in (['CSO', 'CSBVFEE'], ['PPR', 'FSDIS']):
        token = jwt.create_jwt(
            get_claims(roles=[Role.SYSTEM.value],
                       product_code=corp_filing_type[0]), token_header)
        headers = {
            'Authorization': f'Bearer {token}',
            'content-type': 'application/json'
        }
        rv = client.post('/api/v1/payment-requests',
                         data=json.dumps(
                             get_payment_request_with_service_fees(
                                 corp_type=corp_filing_type[0],
                                 filing_type=corp_filing_type[1])),
                         headers=headers)

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

    token = jwt.create_jwt(
        get_claims(roles=[Role.SYSTEM.value], product_code='CSO'),
        token_header)
    headers = {
        'Authorization': f'Bearer {token}',
        'content-type': 'application/json'
    }
    rv = client.post(
        f'/api/v1/accounts/{pay_account.auth_account_id}/payments/queries?page=1&limit=5',
        data=json.dumps({}),
        headers=headers)

    assert rv.status_code == 200
    assert rv.json.get('total') == 1
    assert len(rv.json.get('items')) == 1
    assert rv.json.get('items')[0]['corpTypeCode'] == 'CSO'
Beispiel #9
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