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
def test_get_transactions(app, test_user): t1 = create_transactions()[0] with app.app_context(): insert_transaction(t1) t2 = get_transactions({'username': USERNAME1, 'date': START_DATE1_DATE}).first() assert t2 is not None assert t1['date'] == t2['date'].date()
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}))
def test_deleting_transactions(client, app, auth, test_user): with app.app_context(): add = '/transactions/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 t1s = create_transactions(count=4) t2s = create_transactions(username=USERNAME2, count=2) t1s = t1s + create_transactions(payee=PAYEE2) t2s = t2s + create_transactions(username=USERNAME2, payee=PAYEE2) for transaction in t1s: insert_transaction(transaction) for transaction in t2s: insert_transaction(transaction) assert 5 == len(get_transactions({'username': USERNAME1})) d1 = {'username': USERNAME1, 'payee': PAYEE2} d2 = {'username': USERNAME2, 'payee': PAYEE2} t1id = get_transactions(d1).first().get_id() t2id = get_transactions(d2).first().get_id() change_logged_in_users_transaction = '/transactions/' + t1id + '/delete' change_non_logged_in_users_transaction = '/transactions/' + t2id + '/delete' response = auth.post_and_redirect(change_logged_in_users_transaction) assert 200 == response.status_code response = auth.post_and_redirect( change_non_logged_in_users_transaction) assert 403 == response.status_code assert 4 == len(get_transactions({'username': USERNAME1})) assert 3 == len(get_transactions({'username': USERNAME2})) assert get_transactions({ 'username': USERNAME1, 'payee': PAYEE2 }).count() == 0 assert get_transactions({ 'username': USERNAME2, 'payee': PAYEE2 }).count() != 0
def test_adding_transactions(client, app, auth, test_user): with app.app_context(): add = '/transactions/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) t1s = create_transactions(payer='Payer3', payee='Payee3') assert 1 == len(t1s) for transaction in t1s: response = auth.post_and_redirect('/transactions/add', data=transaction) assert 200 == response.status_code assert b'all' in response.data assert 1 == len(get_transactions_for_user_id(user_id1)) for transaction in t1s: dt = datetime.combine(transaction['date'], datetime.min.time()) assert 1 == len( get_transactions({ 'username': USERNAME1, 'date': dt })) assert get_transactions({ 'username': USERNAME1, 'date': dt }).first().date.date() == transaction['date']
def test_adding_transactions_account(client, app, auth, test_user): with app.app_context(): add = '/transactions/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) t1s = create_transactions(payer='', payee='', count=5) for transaction in t1s: auth.post('/transactions/add', data=transaction) assert len(get_transactions_for_user_id(user_id1)) == 5 assert len(get_transactions({ 'username': USERNAME1, 'payer': 'other' })) == 5
def test_editing_transactions(client, app, auth, test_user): with app.app_context(): add = '/transactions/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) t1s = create_transactions() t2s = create_transactions(username=USERNAME2, payee='other', payer='other', count=3) for transaction in t1s: insert_transaction(transaction) for transaction in t2s: insert_transaction(transaction) assert 1 == len(get_transactions_for_user_id(user_id1)) data1 = {'username': USERNAME1, 'payer': PAYER1} data2 = {'username': USERNAME2, 'payer': 'other'} t1id = get_transactions(data1).first().get_id() t2id = get_transactions(data2).first().get_id() t = create_transactions(USERNAME1, payer='', payee='Payee3', date=START_DATE2_DATE)[0] change_logged_in_users_transaction = '/transactions/' + t1id + '/edit' change_non_logged_in_users_transaction = '/transactions/' + t2id + '/edit' response = auth.post_and_redirect(change_logged_in_users_transaction, data=t) assert 200 == response.status_code response = auth.post_and_redirect( change_non_logged_in_users_transaction, data=t) assert 403 == response.status_code assert 1 == len(get_transactions_for_user_id(user_id1)) assert 0 != get_transactions({ 'username': USERNAME1, 'payee': 'Payee3' }).count() assert t['date'] == get_transactions({ 'username': USERNAME1, 'payee': 'Payee3' }).first().date.date() assert 0 == get_transactions({ 'username': USERNAME2, 'payee': 'Payee3' }).count()
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