Exemplo n.º 1
0
def test_get_accounts_list():
    number_of_accounts = 4
    for i in range(number_of_accounts):
        account_data = Account(name=f"Test {i}", currency=Currency.USD, account_type=AccountType.BANK)
        create_account(account_data)
    accounts = get_accounts_list()
    assert len(accounts) == number_of_accounts
Exemplo n.º 2
0
def test_get_list_of_accounts_api():
    user, token = create_user_and_token_for_tests()
    number_of_accounts = 4
    for i in range(number_of_accounts):
        account_data = Account(name=f"Test {i}", currency=Currency.USD, account_type=AccountType.BANK)
        create_account(account_data)
    response = client.get(
        "/finance/accounts/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_accounts
Exemplo n.º 3
0
def test_delete_account_api():
    user, token = create_user_and_token_for_tests()
    account = create_account(Account(name="Test", currency=Currency.USD, account_type=AccountType.BANK))
    response = client.delete(
        "/finance/accounts/delete",
        data=account.json(),
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_200_OK
Exemplo n.º 4
0
def test_update_account():
    account_data = Account(name="Test", currency=Currency.USD, account_type=AccountType.BANK)
    account = create_account(account_data)
    assert account.id is not None
    assert account.updated is not None

    updated_account = Account(**account_data.dict())
    updated_account.name = "New one"
    updated_account = update_account(updated_account)

    assert updated_account.id == account.id
    assert updated_account.name != account.name
Exemplo n.º 5
0
def test_update_account_api():
    user, token = create_user_and_token_for_tests()
    account = create_account(Account(name="Test", currency=Currency.USD, account_type=AccountType.BANK))
    new_data = Account(**account.dict())
    new_data.name = "Updated"
    response = client.put(
        "/finance/accounts/update",
        data=new_data.json(),
        headers={"Authorization": f"Bearer {token}"},
    )
    assert response.status_code == status.HTTP_200_OK
    response_data = response.json()
    assert response_data["name"] == new_data.name
Exemplo n.º 6
0
def create_account_for_tests(currency: Optional[Currency] = None,
                             order: Optional[int] = None,
                             is_favorite: bool = False) -> Account:
    order = order or 0
    if not currency:
        currency = Currency.USD
    return create_account(
        Account(
            name=get_random_string_and_numbers(12),
            currency=currency,
            account_type=AccountType.BANK,
            order=order,
            is_favorite=is_favorite,
        ))
Exemplo n.º 7
0
def test_create_account():
    account_data = Account(name="Test", currency=Currency.USD, account_type=AccountType.BANK)
    account = create_account(account_data)
    assert account.id is not None
    assert account.updated is not None
Exemplo n.º 8
0
def test_delete_account():
    account = create_account(Account(name="Test", currency=Currency.USD, account_type=AccountType.BANK))
    delete_account(account)
    assert len(get_accounts_list()) == 0
Exemplo n.º 9
0
def create_account_api(data: Account) -> Account:
    return create_account(data)