示例#1
0
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
示例#2
0
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
示例#3
0
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"
示例#4
0
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
示例#5
0
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
示例#6
0
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
示例#7
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
示例#8
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
示例#9
0
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