コード例 #1
0
ファイル: test_crud_accounts.py プロジェクト: Nihisil/Keeper
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
コード例 #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
コード例 #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
コード例 #4
0
ファイル: test_crud_accounts.py プロジェクト: Nihisil/Keeper
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
コード例 #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
コード例 #6
0
ファイル: utils.py プロジェクト: Nihisil/Keeper
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,
        ))
コード例 #7
0
ファイル: test_crud_accounts.py プロジェクト: Nihisil/Keeper
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
コード例 #8
0
ファイル: test_crud_accounts.py プロジェクト: Nihisil/Keeper
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
コード例 #9
0
ファイル: accounts.py プロジェクト: Nihisil/Keeper
def create_account_api(data: Account) -> Account:
    return create_account(data)