Skip to content

Commit

Permalink
[IMP] queue_job: test performance improvement
Browse files Browse the repository at this point in the history
- Create setUpClass() method if necessary
- Switch to setUpClass (if needed) for avoiding repeat the same setup for each test.
- Include context keys for avoiding mail operations overhead.
  • Loading branch information
josep-tecnativa committed Oct 24, 2023
1 parent 55ad859 commit 06414b6
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 13 deletions.
17 changes: 14 additions & 3 deletions queue_job/tests/test_delayable.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@


class TestDelayable(unittest.TestCase):
def setUp(self):
super().setUp()
self.recordset = mock.MagicMock(name="recordset")
@classmethod
def setUpClass(cls):
super().setUpClass()

Check warning on line 13 in queue_job/tests/test_delayable.py

View check run for this annotation

Codecov / codecov/patch

queue_job/tests/test_delayable.py#L13

Added line #L13 was not covered by tests
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {

Check warning on line 16 in queue_job/tests/test_delayable.py

View check run for this annotation

Codecov / codecov/patch

queue_job/tests/test_delayable.py#L16

Added line #L16 was not covered by tests
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.recordset = mock.MagicMock(name="recordset")

Check warning on line 24 in queue_job/tests/test_delayable.py

View check run for this annotation

Codecov / codecov/patch

queue_job/tests/test_delayable.py#L23-L24

Added lines #L23 - L24 were not covered by tests

def test_delayable_set(self):
dl = Delayable(self.recordset)
Expand Down
14 changes: 14 additions & 0 deletions queue_job/tests/test_json_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@


class TestJson(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))

def test_encoder_recordset(self):
demo_user = self.env.ref("base.user_demo")
context = demo_user.context_get()
Expand Down
19 changes: 15 additions & 4 deletions queue_job/tests/test_model_job_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@


class TestJobChannel(common.TransactionCase):
def setUp(self):
super().setUp()
self.Channel = self.env["queue.job.channel"]
self.root_channel = self.Channel.search([("name", "=", "root")])
@classmethod
def setUpClass(cls):
super().setUpClass()
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.Channel = cls.env["queue.job.channel"]
cls.root_channel = cls.Channel.search([("name", "=", "root")])

def test_channel_new(self):
channel = self.Channel.new()
Expand Down
14 changes: 14 additions & 0 deletions queue_job/tests/test_model_job_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@


class TestJobFunction(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))

def test_function_name_compute(self):
function = self.env["queue.job.function"].create(
{"model_id": self.env.ref("base.model_res_users").id, "method": "read"}
Expand Down
14 changes: 14 additions & 0 deletions queue_job/tests/test_queue_job_protected_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@


class TestJobWriteProtected(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))

def test_create_error(self):
with self.assertRaises(exceptions.AccessError):
self.env["queue.job"].create(
Expand Down
23 changes: 17 additions & 6 deletions queue_job/tests/test_wizards.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,28 @@


class TestWizards(common.TransactionCase):
def setUp(self):
super().setUp()
self.job = (
self.env["queue.job"]
@classmethod
def setUpClass(cls):
super().setUpClass()
# Remove this variable in v16 and put instead:
# from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
DISABLED_MAIL_CONTEXT = {
"tracking_disable": True,
"mail_create_nolog": True,
"mail_create_nosubscribe": True,
"mail_notrack": True,
"no_reset_password": True,
}
cls.env = cls.env(context=dict(cls.env.context, **DISABLED_MAIL_CONTEXT))
cls.job = (
cls.env["queue.job"]
.with_context(
_job_edit_sentinel=self.env["queue.job"].EDIT_SENTINEL,
_job_edit_sentinel=cls.env["queue.job"].EDIT_SENTINEL,
)
.create(
{
"uuid": "test",
"user_id": self.env.user.id,
"user_id": cls.env.user.id,
"state": "failed",
"model_name": "queue.job",
"method_name": "write",
Expand Down

0 comments on commit 06414b6

Please sign in to comment.