mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Fix fints account type check (#106082)
This commit is contained in:
parent
7396bc61d7
commit
b27e830997
@ -168,8 +168,8 @@ class FinTsClient:
|
||||
if not account_information:
|
||||
return False
|
||||
|
||||
if 1 <= account_information["type"] <= 9:
|
||||
return True
|
||||
if account_type := account_information.get("type"):
|
||||
return 1 <= account_type <= 9
|
||||
|
||||
if (
|
||||
account_information["iban"] in self.account_config
|
||||
@ -188,8 +188,8 @@ class FinTsClient:
|
||||
if not account_information:
|
||||
return False
|
||||
|
||||
if 30 <= account_information["type"] <= 39:
|
||||
return True
|
||||
if account_type := account_information.get("type"):
|
||||
return 30 <= account_type <= 39
|
||||
|
||||
if (
|
||||
account_information["iban"] in self.holdings_config
|
||||
|
@ -659,6 +659,9 @@ feedparser==6.0.11
|
||||
# homeassistant.components.file
|
||||
file-read-backwards==2.0.0
|
||||
|
||||
# homeassistant.components.fints
|
||||
fints==3.1.0
|
||||
|
||||
# homeassistant.components.fitbit
|
||||
fitbit==0.3.1
|
||||
|
||||
|
1
tests/components/fints/__init__.py
Normal file
1
tests/components/fints/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
"""Tests for FinTS component."""
|
95
tests/components/fints/test_client.py
Normal file
95
tests/components/fints/test_client.py
Normal file
@ -0,0 +1,95 @@
|
||||
"""Tests for the FinTS client."""
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fints.client import BankIdentifier, FinTSOperations
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.fints.sensor import (
|
||||
BankCredentials,
|
||||
FinTsClient,
|
||||
SEPAAccount,
|
||||
)
|
||||
|
||||
BANK_INFORMATION = {
|
||||
"bank_identifier": BankIdentifier(country_identifier="280", bank_code="50010517"),
|
||||
"currency": "EUR",
|
||||
"customer_id": "0815",
|
||||
"owner_name": ["SURNAME, FIRSTNAME"],
|
||||
"subaccount_number": None,
|
||||
"supported_operations": {
|
||||
FinTSOperations.GET_BALANCE: True,
|
||||
FinTSOperations.GET_CREDIT_CARD_TRANSACTIONS: False,
|
||||
FinTSOperations.GET_HOLDINGS: False,
|
||||
FinTSOperations.GET_SCHEDULED_DEBITS_MULTIPLE: False,
|
||||
FinTSOperations.GET_SCHEDULED_DEBITS_SINGLE: False,
|
||||
FinTSOperations.GET_SEPA_ACCOUNTS: True,
|
||||
FinTSOperations.GET_STATEMENT: False,
|
||||
FinTSOperations.GET_STATEMENT_PDF: False,
|
||||
FinTSOperations.GET_TRANSACTIONS: True,
|
||||
FinTSOperations.GET_TRANSACTIONS_XML: False,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
(
|
||||
"account_number",
|
||||
"iban",
|
||||
"product_name",
|
||||
"account_type",
|
||||
"expected_balance_result",
|
||||
"expected_holdings_result",
|
||||
),
|
||||
[
|
||||
("GIRO1", "GIRO1", "Valid balance account", 5, True, False),
|
||||
(None, None, "Invalid account", None, False, False),
|
||||
("GIRO2", "GIRO2", "Account without type", None, False, False),
|
||||
("GIRO3", "GIRO3", "Balance account from fallback", None, True, False),
|
||||
("DEPOT1", "DEPOT1", "Valid holdings account", 33, False, True),
|
||||
("DEPOT2", "DEPOT2", "Holdings account from fallback", None, False, True),
|
||||
],
|
||||
)
|
||||
async def test_account_type(
|
||||
account_number: Optional[str],
|
||||
iban: Optional[str],
|
||||
product_name: str,
|
||||
account_type: Optional[int],
|
||||
expected_balance_result: bool,
|
||||
expected_holdings_result: bool,
|
||||
) -> None:
|
||||
"""Check client methods is_balance_account and is_holdings_account."""
|
||||
credentials = BankCredentials(
|
||||
blz=1234, login="test", pin="0000", url="https://example.com"
|
||||
)
|
||||
account_config = {"GIRO3": True}
|
||||
holdings_config = {"DEPOT2": True}
|
||||
|
||||
client = FinTsClient(
|
||||
credentials=credentials,
|
||||
name="test",
|
||||
account_config=account_config,
|
||||
holdings_config=holdings_config,
|
||||
)
|
||||
|
||||
client._account_information_fetched = True
|
||||
client._account_information = {
|
||||
iban: BANK_INFORMATION
|
||||
| {
|
||||
"account_number": account_number,
|
||||
"iban": iban,
|
||||
"product_name": product_name,
|
||||
"type": account_type,
|
||||
}
|
||||
}
|
||||
|
||||
sepa_account = SEPAAccount(
|
||||
iban=iban,
|
||||
bic="BANCODELTEST",
|
||||
accountnumber=account_number,
|
||||
subaccount=None,
|
||||
blz="12345",
|
||||
)
|
||||
|
||||
assert client.is_balance_account(sepa_account) == expected_balance_result
|
||||
assert client.is_holdings_account(sepa_account) == expected_holdings_result
|
Loading…
x
Reference in New Issue
Block a user