def test_get_finance_categories_list(): number_of_finance_categories = 4 for i in range(number_of_finance_categories): category = create_finance_category(FinanceCategory(name=f"Test {i}")) create_transaction_for_tests(amount=i + 1, category=category, transaction_type=TransactionType.REGULAR) finance_categories = get_finance_categories_list() assert len(finance_categories) == number_of_finance_categories assert finance_categories[0].amount is not None
def test_get_employers_list(): account = create_account_for_tests() number_of_employers = 4 for i in range(number_of_employers): employer = create_employer(Employer(name=f"Test {i}", associated_account_id=account.id)) create_transaction_for_tests(amount=i + 1, employer=employer) employers = get_employers_list() assert len(employers) == number_of_employers assert employers[0].earnings == 4 assert employers[0].earnings_currency is not None assert employers[1].earnings == 3 assert employers[2].earnings == 2 assert employers[3].earnings == 1
def test_get_list_of_transactions_api(): user, token = create_user_and_token_for_tests() number_of_transactions = 4 for i in range(number_of_transactions): create_transaction_for_tests(i + 1) response = client.get( "/finance/transactions/get-list", headers={"Authorization": f"Bearer {token}"}, ) assert response.status_code == status.HTTP_200_OK response_data = response.json() assert len(response_data) == number_of_transactions assert response_data[0]["account"][ "id"] is not None, "Transaction should include account information"
def test_update_transaction_amount(): old_amount = 100 transaction = create_transaction_for_tests(old_amount, TransactionType.REGULAR) account = get_account_by_id(transaction.account_id) assert account.balance == old_amount * -1 new_amount = 50 transaction.amount = new_amount update_transaction(transaction, old_amount) account = get_account_by_id(transaction.account_id) assert account.balance == new_amount * -1
def test_delete_transaction_api(): user, token = create_user_and_token_for_tests() transaction = create_transaction_for_tests(100) response = client.delete( "/finance/transactions/delete", data=transaction.json(), headers={"Authorization": f"Bearer {token}"}, ) assert response.status_code == status.HTTP_200_OK response_data = response.json() # updated account is present in response assert response_data["account"]["id"] == transaction.account_id
def test_delete_regular_transaction(): amount = 100 transaction = create_transaction_for_tests( amount=amount, transaction_type=TransactionType.REGULAR) account = get_account_by_id(transaction.account_id) assert account.balance == amount * -1 delete_transaction(transaction) assert len(get_transactions_list()) == 0 account = get_account_by_id(transaction.account_id) assert account.balance == 0
def test_delete_income_transaction(): amount = 100 transaction = create_transaction_for_tests( amount=amount, transaction_type=TransactionType.INCOME) account = get_account_by_id(transaction.account_id) assert account.balance == amount delete_transaction(transaction) assert len(get_transactions_list()) == 0 account = get_account_by_id(transaction.account_id) assert account.balance == 0
def test_update_transaction_api(): user, token = create_user_and_token_for_tests() transaction = create_transaction_for_tests(100) account = get_account_by_id(transaction.account_id) assert account.balance == transaction.amount transaction.amount = 200 response = client.put( "/finance/transactions/update", data=transaction.json(), headers={"Authorization": f"Bearer {token}"}, ) assert response.status_code == status.HTTP_200_OK response_data = response.json() assert response_data["account"]["id"] == account.id assert response_data["account"]["balance"] == transaction.amount
def test_get_transactions_list(): number_of_transactions = 4 for i in range(number_of_transactions): create_transaction_for_tests(i + 1) transactions = get_transactions_list() assert len(transactions) == number_of_transactions