Skip to content

Commit 713cf3b

Browse files
committed
[FIX] pre-commit & unit tests errors
1 parent daa53f8 commit 713cf3b

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

account_statement_import_online_wise/models/online_bank_statement_provider_wise.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def values_wise_profile(self):
5050
except BaseException:
5151
_logger.warning("Unable to get profiles", exc_info=True)
5252
return []
53+
5354
return list(
5455
map(
5556
lambda entry: (
5657
str(entry["id"]),
57-
"%s %s (personal)"
58-
% (
58+
"{} {} (personal)".format(
5959
entry["details"]["firstName"],
6060
entry["details"]["lastName"],
6161
)
@@ -253,7 +253,7 @@ def _wise_transaction_to_lines(self, transaction):
253253
"amount": str(fees_value),
254254
"date": date,
255255
"partner_name": "Wise",
256-
"unique_import_id": "%s-FEE" % unique_import_id,
256+
"unique_import_id": f"{unique_import_id}-FEE",
257257
"payment_ref": _("Transaction fee for %s") % reference_number,
258258
}
259259
]
@@ -281,7 +281,9 @@ def _wise_retrieve(self, url, api_key, private_key=None):
281281
if e.code != 403 or e.headers.get("X-2FA-Approval-Result") != "REJECTED":
282282
raise e
283283
if not private_key:
284-
raise UserError(_("Strong Customer Authentication is not configured"))
284+
raise UserError(
285+
_("Strong Customer Authentication is not configured")
286+
) from e
285287
one_time_token = e.headers["X-2FA-Approval"]
286288
signature = private_key.sign(
287289
one_time_token.encode(),
@@ -306,7 +308,7 @@ def _wise_urlopen(self, url, api_key, ott=None, signature=None):
306308
if not api_key:
307309
raise UserError(_("No API key specified!"))
308310
request = urllib.request.Request(url)
309-
request.add_header("Authorization", "Bearer %s" % api_key)
311+
request.add_header("Authorization", f"Bearer {api_key}")
310312
if ott and signature:
311313
request.add_header("X-2FA-Approval", ott)
312314
request.add_header("X-Signature", signature)
@@ -335,9 +337,9 @@ def _onchange_wise_certificate_private_key(self):
335337
)
336338
.decode()
337339
)
338-
except BaseException:
340+
except BaseException as exception:
339341
_logger.warning("Unable to parse key", exc_info=True)
340-
raise UserError(_("Unable to parse key"))
342+
raise UserError(_("Unable to parse key")) from exception
341343

342344
def _wise_generate_key(self):
343345
self.ensure_one()

account_statement_import_online_wise/tests/test_account_statement_import_online_wise.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
from dateutil.relativedelta import relativedelta
1212

1313
from odoo import fields
14-
from odoo.tests import common
15-
from odoo.tests import Form
14+
from odoo.tests import Form, common
1615

1716
_module_ns = "odoo.addons.account_statement_import_online_wise"
1817
_provider_class = (
@@ -126,7 +125,7 @@ def test_values_wise_profile(self):
126125
return_value=mocked_response,
127126
):
128127
values_wise_profile = self.OnlineBankStatementProvider.with_context(
129-
{"api_base": "https://example.com", "api_key": "dummy"}
128+
api_base="https://example.com", api_key="dummy"
130129
).values_wise_profile()
131130
self.assertEqual(
132131
values_wise_profile,
@@ -138,18 +137,18 @@ def test_values_wise_profile(self):
138137

139138
def test_values_wise_profile_no_key(self):
140139
values_wise_profile = self.OnlineBankStatementProvider.with_context(
141-
{"api_base": "https://example.com"}
140+
api_base="https://example.com"
142141
).values_wise_profile()
143142
self.assertEqual(values_wise_profile, [])
144143

145144
def test_values_wise_profile_error(self):
146145
values_wise_profile = []
147146
with mock.patch(
148147
_provider_class + "._wise_retrieve",
149-
side_effect=lambda: Exception(),
148+
side_effect=Exception("Test error"),
150149
):
151150
values_wise_profile = self.OnlineBankStatementProvider.with_context(
152-
{"api_base": "https://example.com", "api_key": "dummy"}
151+
api_base="https://example.com", api_key="dummy"
153152
).values_wise_profile()
154153
self.assertEqual(values_wise_profile, [])
155154

@@ -764,8 +763,6 @@ def test_transaction_parse_8(self):
764763
"name": "Converted 7.93 USD to 6.93 EUR",
765764
"payment_ref": "BALANCE-123456789: Converted 7.93 USD to 6.93 EUR",
766765
"amount": "-7.88",
767-
"amount_currency": "-6.93",
768-
"foreign_currency_id": self.currency_eur.id,
769766
"unique_import_id": "DEBIT-BALANCE-123456789-946684800",
770767
},
771768
)

0 commit comments

Comments
 (0)