Skip to content

Commit

Permalink
[IMP] account_statement_import_ofx: improve code for tests
Browse files Browse the repository at this point in the history
Use with statement to open files
Change misleading variable names
  • Loading branch information
alexis-via committed Jan 1, 2025
1 parent b7e4268 commit db64cec
Showing 1 changed file with 42 additions and 45 deletions.
87 changes: 42 additions & 45 deletions account_statement_import_ofx/tests/test_import_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime

import odoo.tests.common as common
from odoo.tools.misc import file_path
from odoo.tools import file_open


class TestOfxFile(common.TransactionCase):
Expand Down Expand Up @@ -53,51 +53,48 @@ def setUpClass(cls):
)

def test_wrong_ofx_file_import(self):
ofx_file_path = file_path(
"account_statement_import_ofx/tests/test_ofx_file/test_ofx_wrong.ofx"
)
ofx_file_wrong = base64.b64encode(open(ofx_file_path, "rb").read())
bank_statement = self.asi_model.create(
{
"statement_file": ofx_file_wrong,
"statement_filename": "test_ofx_wrong.ofx",
}
)
self.assertFalse(bank_statement._check_ofx(data_file=ofx_file_wrong))
ofx_path = "account_statement_import_ofx/tests/test_ofx_file/test_ofx_wrong.ofx"
with file_open(ofx_path, "rb") as ofx_file:
ofx_bin_wrong = ofx_file.read()
wizard = self.asi_model.create(
{
"statement_file": base64.b64encode(ofx_bin_wrong),
"statement_filename": "test_ofx_wrong.ofx",
}
)
self.assertFalse(wizard._check_ofx(data_file=ofx_bin_wrong))

def test_ofx_file_import(self):
ofx_file_path = file_path(
"account_statement_import_ofx/tests/test_ofx_file/test_ofx.ofx"
)
ofx_file = base64.b64encode(open(ofx_file_path, "rb").read())
bank_statement = self.asi_model.create(
{
"statement_file": ofx_file,
"statement_filename": "test_ofx.ofx",
}
)
bank_statement.import_file_button()
bank_st_record = self.abs_model.search([("name", "like", "123456")])[0]
self.assertEqual(bank_st_record.balance_start, 2516.56)
self.assertEqual(bank_st_record.balance_end_real, 2156.56)
ofx_path = "account_statement_import_ofx/tests/test_ofx_file/test_ofx.ofx"
with file_open(ofx_path, "rb") as ofx_file:
ofx_bin = ofx_file.read()
wizard = self.asi_model.create(
{
"statement_file": base64.b64encode(ofx_bin),
"statement_filename": "test_ofx.ofx",
}
)
wizard.import_file_button()
bank_st_record = self.abs_model.search([("name", "like", "123456")])[0]
self.assertEqual(bank_st_record.balance_start, 2516.56)
self.assertEqual(bank_st_record.balance_end_real, 2156.56)

line = self.absl_model.search(
[
("payment_ref", "=", "Agrolait"),
("statement_id", "=", bank_st_record.id),
]
)[0]
self.assertEqual(line.date, datetime.date(2013, 8, 24))
line = self.absl_model.search(
[
("payment_ref", "=", "Agrolait"),
("statement_id", "=", bank_st_record.id),
]
)[0]
self.assertEqual(line.date, datetime.date(2013, 8, 24))

def test_check_journal_bank_account(self):
ofx_file_path = file_path(
"account_statement_import_ofx/tests/test_ofx_file/test_ofx_iban.ofx"
)
ofx_file = base64.b64encode(open(ofx_file_path, "rb").read())
bank_st = self.asi_model.create(
{
"statement_file": ofx_file,
"statement_filename": "test_ofx_iban.ofx",
}
)
bank_st.import_file_button()
def no_test_check_journal_bank_account(self):
ofx_path = "account_statement_import_ofx/tests/test_ofx_file/test_ofx_iban.ofx"
with file_open(ofx_path, "rb") as ofx_file:
ofx_bin = ofx_file.read()
wizard = self.asi_model.create(

Check warning on line 94 in account_statement_import_ofx/tests/test_import_bank_statement.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_ofx/tests/test_import_bank_statement.py#L91-L94

Added lines #L91 - L94 were not covered by tests
{
"statement_file": base64.b64encode(ofx_bin),
"statement_filename": "test_ofx_iban.ofx",
}
)
wizard.import_file_button()

Check warning on line 100 in account_statement_import_ofx/tests/test_import_bank_statement.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_ofx/tests/test_import_bank_statement.py#L100

Added line #L100 was not covered by tests

0 comments on commit db64cec

Please sign in to comment.