[IMP] account_payment_order: test performance improvement

- Create setUpClass method
- Switch to setUpClass (if needed) for avoiding repeat the same setup for each test.
- Include context keys for avoiding mail operations overhead.
This commit is contained in:
josep-tecnativa
2023-10-16 12:27:21 +02:00
parent 54e2dc8b83
commit 1c9703f53c
5 changed files with 70 additions and 17 deletions

View File

@@ -14,6 +14,16 @@ class TestAccountPayment(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
Method_get_payment_method_information = (
AccountPaymentMethod._get_payment_method_information

View File

@@ -6,6 +6,20 @@ from odoo.tests.common import TransactionCase
class TestBank(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
def test_bank(self):
bank = self.env["res.bank"].search([], limit=1)
self.assertTrue(bank)

View File

@@ -9,14 +9,23 @@ from odoo.addons.account.models.account_payment_method import AccountPaymentMeth
class TestPaymentMode(TransactionCase):
def setUp(self):
super(TestPaymentMode, self).setUp()
@classmethod
def setUpClass(cls):
super(TestPaymentMode, cls).setUpClass()
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
Method_get_payment_method_information = (
AccountPaymentMethod._get_payment_method_information
)
@classmethod
def _get_payment_method_information(cls):
res = Method_get_payment_method_information(cls)
res["IN"] = {"mode": "multi", "domain": [("type", "=", "bank")]}
@@ -25,24 +34,24 @@ class TestPaymentMode(TransactionCase):
return res
# Company
self.company = self.env.ref("base.main_company")
cls.company = cls.env.ref("base.main_company")
self.journal_c1 = self.env["account.journal"].create(
cls.journal_c1 = cls.env["account.journal"].create(
{
"name": "Journal 1",
"code": "J1",
"type": "bank",
"company_id": self.company.id,
"company_id": cls.company.id,
}
)
self.account = self.env["account.account"].search(
[("reconcile", "=", True), ("company_id", "=", self.company.id)], limit=1
cls.account = cls.env["account.account"].search(
[("reconcile", "=", True), ("company_id", "=", cls.company.id)], limit=1
)
self.manual_out = self.env.ref("account.account_payment_method_manual_out")
cls.manual_out = cls.env.ref("account.account_payment_method_manual_out")
self.manual_in = self.env.ref("account.account_payment_method_manual_in")
cls.manual_in = cls.env.ref("account.account_payment_method_manual_in")
with patch.object(
AccountPaymentMethod,
@@ -50,7 +59,7 @@ class TestPaymentMode(TransactionCase):
_get_payment_method_information,
):
self.electronic_out = self.env["account.payment.method"].create(
cls.electronic_out = cls.env["account.payment.method"].create(
{
"name": "Electronic Out",
"code": "electronic_out",
@@ -58,14 +67,14 @@ class TestPaymentMode(TransactionCase):
}
)
self.payment_mode_c1 = self.env["account.payment.mode"].create(
cls.payment_mode_c1 = cls.env["account.payment.mode"].create(
{
"name": "Direct Debit of suppliers from Bank 1",
"bank_account_link": "variable",
"payment_method_id": self.manual_out.id,
"company_id": self.company.id,
"fixed_journal_id": self.journal_c1.id,
"variable_journal_ids": [(6, 0, [self.journal_c1.id])],
"payment_method_id": cls.manual_out.id,
"company_id": cls.company.id,
"fixed_journal_id": cls.journal_c1.id,
"variable_journal_ids": [(6, 0, [cls.journal_c1.id])],
}
)

View File

@@ -17,6 +17,16 @@ class TestPaymentOrderInboundBase(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.company = cls.company_data["company"]
cls.env.user.company_id = cls.company.id
cls.partner = cls.env["res.partner"].create(

View File

@@ -17,6 +17,16 @@ class TestPaymentOrderOutboundBase(AccountTestInvoicingCommon):
@classmethod
def setUpClass(cls, chart_template_ref=None):
super().setUpClass(chart_template_ref=chart_template_ref)
cls.env = cls.env(
context=dict(
cls.env.context,
mail_create_nolog=True,
mail_create_nosubscribe=True,
mail_notrack=True,
no_reset_password=True,
tracking_disable=True,
)
)
cls.company = cls.company_data["company"]
cls.env.user.company_id = cls.company.id
cls.partner = cls.env["res.partner"].create(