-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_job_auto_delay.py
More file actions
37 lines (29 loc) · 1.34 KB
/
Copy pathtest_job_auto_delay.py
File metadata and controls
37 lines (29 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright 2020 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)
from odoo.addons.queue_job.job import Job
from .common import JobCommonCase
class TestJobAutoDelay(JobCommonCase):
"""Test auto delay of jobs"""
def test_auto_delay(self):
"""method decorated by @job_auto_delay is automatically delayed"""
result = self.env["test.queue.job"].delay_me(1, kwarg=2)
self.assertTrue(isinstance(result, Job))
self.assertEqual(result.args, (1,))
self.assertEqual(result.kwargs, {"kwarg": 2})
def test_auto_delay_options(self):
"""method automatically delayed une <method>_job_options arguments"""
result = self.env["test.queue.job"].delay_me_options()
self.assertTrue(isinstance(result, Job))
self.assertEqual(result.identity_key, "my_job_identity")
def test_auto_delay_inside_job(self):
"""when a delayed job is processed, it must not delay itself"""
job_ = self.env["test.queue.job"].delay_me(1, kwarg=2)
self.assertTrue(job_.perform(), (1, 2))
def test_auto_delay_force_sync(self):
"""method forced to run synchronously"""
result = (
self.env["test.queue.job"]
.with_context(_job_force_sync=True)
.delay_me(1, kwarg=2)
)
self.assertTrue(result, (1, 2))