Skip to content

Commit

Permalink
[fix] defaulting numbers to zero instead of None
Browse files Browse the repository at this point in the history
  • Loading branch information
grindsa committed Dec 27, 2024
1 parent fff6511 commit 2f8f3ab
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions dkb_robo/portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _details(self, account: Dict[str, str], aid: str) -> Dict[str, str]:
for my_field, dkb_field in mapping_dic.items():
if my_field == 'limit':
try:
output_dic[my_field] = float(account.get('attributes', {}).get(dkb_field, None))
output_dic[my_field] = float(account.get('attributes', {}).get(dkb_field, 0))
except Exception as exc:
self.logger.error('limit conversion error: %s', exc)
output_dic[my_field] = None
Expand Down Expand Up @@ -265,7 +265,7 @@ def _details(self, card: Dict[str, str], cid: str) -> Dict[str, str]:
self.logger.debug('portfolio.Card._details()\n')

try:
limit = float(card.get('attributes', {}).get('limit', {}).get('value', None))
limit = float(card.get('attributes', {}).get('limit', {}).get('value', 0))
except Exception as exc:
self.logger.error('limit conversion error: %s', exc)
limit = None
Expand Down
2 changes: 1 addition & 1 deletion dkb_robo/standingorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _filter(self, full_list: Dict[str, str]) -> List[Dict[str, str]]:
for ele in full_list['data']:

try:
amount = float(ele.get('attributes', {}).get('amount', {}).get('value', None))
amount = float(ele.get('attributes', {}).get('amount', {}).get('value', 0))
except Exception as err:
self.logger.error('api.StandingOrder._filter() error: %s', err)
amount = None
Expand Down
12 changes: 3 additions & 9 deletions test/test_portfolio.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,7 @@ def test_018__sort(self):
'status': {'category': 'active'},
'transactions': None,
'type': 'debitcard'}}
with self.assertLogs('dkb_robo', level='INFO') as lcm:
self.assertEqual(result, self.overview._sort(data))
self.assertIn("ERROR:dkb_robo:limit conversion error: float() argument must be a string or a real number, not 'NoneType'", lcm.output)
self.assertEqual(result, self.overview._sort(data))

def test_019__sort(self):
""" test _sort() """
Expand Down Expand Up @@ -423,9 +421,7 @@ def test_019__sort(self):
'productgroup': None,
'transactions': 'https://banking.dkb.de/api/broker/brokerage-accounts/baccountid1/positions?include=instrument%2Cquote',
'type': 'depot'}}
with self.assertLogs('dkb_robo', level='INFO') as lcm:
self.assertEqual(result, self.overview._sort(data))
self.assertIn("ERROR:dkb_robo:limit conversion error: float() argument must be a string or a real number, not 'NoneType'", lcm.output)
self.assertEqual(result, self.overview._sort(data))

class TestAccount(unittest.TestCase):
""" test class """
Expand Down Expand Up @@ -455,9 +451,7 @@ def test_022__balance(self):
def test_023__details(self):
""" test _details() """
account = {'attributes': {'iban': 'iban', 'bic': 'bic', 'accountNumber': 'accountNumber', 'bankCode': 'bankCode', 'accountType': 'accountType', 'balance': 'balance'}}
with self.assertLogs('dkb_robo', level='INFO') as lcm:
self.assertEqual({'type': 'account', 'name': None, 'id': 'aid', 'transactions': 'https://banking.dkb.de/api/accounts/accounts/aid/transactions', 'date': None, 'iban': 'iban', 'account': 'iban', 'holdername': None, 'limit': None}, self.account._details(account, 'aid'))
self.assertIn("ERROR:dkb_robo:limit conversion error: float() argument must be a string or a real number, not 'NoneType'", lcm.output)
self.assertEqual({'type': 'account', 'name': None, 'id': 'aid', 'transactions': 'https://banking.dkb.de/api/accounts/accounts/aid/transactions', 'date': None, 'iban': 'iban', 'account': 'iban', 'holdername': None, 'limit': 0.0}, self.account._details(account, 'aid'))

@patch('dkb_robo.portfolio.Account._balance')
@patch('dkb_robo.portfolio.Account._details')
Expand Down
6 changes: 2 additions & 4 deletions test/test_standingorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ def test_007__filter(self):
}
}
}]}
result = [{'amount': None, 'currencycode': None, 'purpose': 'description', 'recpipient': 'cardname', 'creditoraccount': {'iban': 'crediban', 'bic': 'credbic'}, 'interval': {'from': '2020-01-01', 'until': '2025-12-01', 'frequency': 'monthly', 'nextExecutionAt': '2020-02-01'}}]
with self.assertLogs('dkb_robo', level='INFO') as lcm:
self.assertEqual(result, self.dkb._filter(full_list))
self.assertIn("ERROR:dkb_robo:api.StandingOrder._filter() error: float() argument must be a string or a real number, not 'NoneType'", lcm.output)
result = [{'amount': 0.0, 'currencycode': None, 'purpose': 'description', 'recpipient': 'cardname', 'creditoraccount': {'iban': 'crediban', 'bic': 'credbic'}, 'interval': {'from': '2020-01-01', 'until': '2025-12-01', 'frequency': 'monthly', 'nextExecutionAt': '2020-02-01'}}]
self.assertEqual(result, self.dkb._filter(full_list))

if __name__ == '__main__':

Expand Down

0 comments on commit 2f8f3ab

Please sign in to comment.