Exemple #1
0
def test_bulk_update(app):
    with app.app_context():
        frequency = Frequency.objects(label='monthly').first()
        series = insert_series(
            USERNAME1,
            SERIES_NAME,
            PAYER1,
            PAYEE1,
            AMOUNT,
            START_DATE1_DATE,
            END_DATE1_DATE,
            frequency)
        assert 25 == get_transactions_for_username(USERNAME1).count()
        assert series is not None
        assert 25 == len(series.transactions)
        assert get_series_by_id(series.id) is not None
        assert 25 == len(get_series_by_id(series.id).transactions)
        assert 1 == len(get_series_by_username(USERNAME1))
        assert 1 == len(get_series(USERNAME1, {}))
        assert 1 == len(get_series(USERNAME1, {'payer': PAYER1}))

        from_data = {'username': USERNAME1, 'payer': PAYER1}
        to_data = {'username': USERNAME1, 'payer': PAYER2}

        bulk_update(from_data, to_data)
        assert 25 == get_transactions_for_username(USERNAME1).count()
        assert series is not None
        assert 25 == len(series.transactions)
        assert get_series_by_id(series.id) is not None
        assert 25 == len(get_series_by_id(series.id).transactions)
        assert 1 == len(get_series_by_username(USERNAME1))
        assert 1 == len(get_series(USERNAME1, {}))
        assert 1 == len(get_series(USERNAME1, {'payer': PAYER2}))
        for transaction in get_series_by_id(series.id).transactions:
            assert PAYER2 == transaction.payer.account_name
Exemple #2
0
def test_delete_series(app):
    with app.app_context():
        frequency = Frequency.objects(label='monthly').first()
        series = insert_series(
            USERNAME1,
            SERIES_NAME,
            PAYER1,
            PAYEE1,
            AMOUNT,
            START_DATE1_DATE,
            END_DATE1_DATE,
            frequency)
        assert 25 == get_transactions_for_username(USERNAME1).count()
        assert series is not None
        transactions = series.transactions
        assert 25 == len(transactions)
        assert get_series_by_id(series.id) is not None
        assert 25 == len(get_series_by_id(series.id).transactions)
        assert 1 == len(get_series_by_username(USERNAME1))
        assert 1 == len(get_series(USERNAME1, {}))
        assert 1 == len(get_series(USERNAME1, {'payer': PAYER1}))
        delete_series(series.id)
        assert get_series_by_id(series.id) is None
        assert 0 == len(get_series_by_username(USERNAME1))
        assert get_transaction(transactions[0].id) is None
        assert 0 == len(get_series(USERNAME1, {}))
        assert 0 == len(get_series(USERNAME1, {'payer': PAYER1}))
Exemple #3
0
def test_adding_series(client, app, auth, test_user):
    with app.app_context():
        add = '/series/add'
        response = auth.post_and_redirect(add)
        assert b"login" in response.data
        assert b"register" in response.data

        auth.login()
        response = auth.post_and_redirect(add)
        assert b"add" in response.data

        user_id1 = test_user.get_user_id(USERNAME1)

        response = auth.post_and_redirect('/series/add', data=STANDARD_SERIES1)
        assert 200 == response.status_code
        assert b"all" in response.data

        assert 1 == len(get_series_by_username(USERNAME1))
        assert 25 == len(get_transactions_for_user_id(user_id1))

        date = datetime.combine(START_DATE1_DATE, datetime.min.time())
        assert 1 == len(get_transactions({
            'username': USERNAME1,
            'date': date
        }))
        assert START_DATE1_DATE == get_transactions({
            'username': USERNAME1,
            'date': date
        }).first().date
Exemple #4
0
def test_deleting_series(client, app, auth, test_user):
    with app.app_context():
        add = '/series/add'
        response = auth.post_and_redirect(add)
        assert b"login" in response.data
        assert b"register" in response.data

        auth.login()
        response = auth.post_and_redirect(add)
        assert b"add" in response.data

        user_id1 = test_user.get_user_id(USERNAME1)

        response = auth.post_and_redirect('/series/add', data=STANDARD_SERIES1)
        assert b"all" in response.data

        assert 1 == len(get_series_by_username(USERNAME1))
        assert 25 == len(get_transactions_for_user_id(user_id1))

        s1 = {'payee': PAYEE1}
        s1id = get_series(USERNAME1, s1).first().get_id()

        change_logged_in_users_series = '/series/' + s1id + '/delete'

        response = auth.post_and_redirect(change_logged_in_users_series)

        assert 200 == response.status_code

        dt = datetime.combine(START_DATE1_DATE, datetime.min.time())
        assert 0 == len(get_transactions({'username': USERNAME1, 'date': dt}))
Exemple #5
0
def all_series():
    series = list(get_series_by_username(g.username))
    return render_template('series/all.html', series=series)
Exemple #6
0
def test_adding_accounts(client, app, auth, test_user):
    with app.app_context():
        add = '/series/add'
        response = auth.post_and_redirect(add)
        assert b"login" in response.data
        assert b"register" in response.data

        auth.login()
        response = auth.post_and_redirect(add)
        assert b"add" in response.data

        user_id1 = test_user.get_user_id(USERNAME1)

        a1s = create_accounts()
        assert 1 == len(a1s)

        for account in a1s:
            response = auth.post('/accounts/add', data=account)
            assert b"all" in response.data

        assert 3 == len(get_accounts_by_username(USERNAME1))

        for account in a1s:
            date = datetime.combine(account['account_opened_date'],
                                    datetime.min.time())
            accounts = get_accounts({
                'username': USERNAME1,
                'account_opened_date': date
            })
            assert 1 == len(accounts)
            assert account['account_opened_date'] == accounts.first(
            ).account_opened_date.date()

        add = '/series/add'
        response = auth.post_and_redirect(add)
        assert b"add" in response.data

        response = auth.post_and_redirect('/series/add', data=STANDARD_SERIES1)
        assert b"all" in response.data

        assert 1 == len(get_series_by_username(USERNAME1))
        assert 25 == len(get_transactions_for_user_id(user_id1))

        s1 = {'payee': PAYEE1}
        s1id = get_series(USERNAME1, s1).first().get_id()

        change_logged_in_users_series = '/series/' + s1id + '/edit'

        response = auth.post_and_redirect(change_logged_in_users_series,
                                          data=STANDARD_SERIES_ACCOUNT)

        assert b'error' not in response.data

        assert 200 == response.status_code
        assert 1 == len(get_series_by_username(USERNAME1))
        date = datetime.combine(START_DATE1_DATE, datetime.min.time())
        assert 1 == len(get_transactions({
            'username': USERNAME1,
            'date': date
        }))
        assert START_DATE1_DATE == get_transactions({
            'username': USERNAME1,
            'date': date
        }).first().date
        assert ACCOUNT_NAME1 == get_transactions({
            'username': USERNAME1,
            'payee': ACCOUNT_NAME1
        }).first().payee.account_name