Beispiel #1
0
def test_delete_account(app):
    with app.app_context():
        data = {
            'username': USERNAME1,
            'account_name': ACCOUNT_NAME1,
            'account_opened_date': ACCOUNT_OPENED_DATE1,
        }
        account = insert_account(data)
        assert account is not None
        assert get_account_by_id(account.id) is not None
        assert 3 == len(get_accounts_by_username(USERNAME1))
        assert 3 == len(get_accounts({'username': USERNAME1}))
        assert 1 == len(
            get_accounts({
                'username': USERNAME1,
                'account_name': ACCOUNT_NAME1
            }))
        delete_account(account.id)
        assert get_account_by_id(account.id) is None
        assert 2 == len(get_accounts_by_username(USERNAME1))
        assert 2 == len(get_accounts({
            'username': USERNAME1,
        }))
        assert 0 == len(
            get_accounts({
                'username': USERNAME1,
                'account_name': ACCOUNT_NAME1
            }))
Beispiel #2
0
def test_deleting_accounts(client, app, auth, test_user):
    with app.app_context():
        add = '/accounts/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

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

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

        assert 3 == len(get_accounts_by_username(USERNAME1))

        a1 = {'username': USERNAME1, 'account_name': 'ACCOUNT_NAME1'}
        a1id = get_accounts(copy.deepcopy(a1)).first().get_id()

        change_logged_in_users_series = '/accounts/' + a1id + '/delete'

        response = auth.post_and_redirect(change_logged_in_users_series)

        assert 200 == response.status_code

        assert 0 == len(get_accounts(a1))
Beispiel #3
0
def all_accounts():
    accounts = list(get_accounts_by_username(g.username))
    return render_template('accounts/all.html', accounts=accounts)
Beispiel #4
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