Skip to content

Commit

Permalink
[MIG] test_queue_job: Migration to 18.0
Browse files Browse the repository at this point in the history
  • Loading branch information
QuocDuong1306 authored and thienvh332 committed Oct 15, 2024
1 parent eb6c5dd commit bb4b6f6
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 27 deletions.
2 changes: 1 addition & 1 deletion test_queue_job/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{
"name": "Queue Job Tests",
"version": "17.0.1.0.1",
"version": "18.0.1.0.0",
"author": "Camptocamp,Odoo Community Association (OCA)",
"license": "LGPL-3",
"category": "Generic Modules",
Expand Down
6 changes: 3 additions & 3 deletions test_queue_job/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_test_queue_job,access_test_queue_job,model_test_queue_job,,1,1,1,1
access_test_queue_channel,access_test_queue_channel,model_test_queue_channel,,1,1,1,1
access_test_related_action,access_test_related_action,model_test_related_action,,1,1,1,1
access_test_queue_job,access_test_queue_job,model_test_queue_job,queue_job.group_queue_job_manager,1,1,1,1
access_test_queue_channel,access_test_queue_channel,model_test_queue_channel,queue_job.group_queue_job_manager,1,1,1,1
access_test_related_action,access_test_related_action,model_test_related_action,queue_job.group_queue_job_manager,1,1,1,1
2 changes: 1 addition & 1 deletion test_queue_job/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ def setUpClass(cls):
def _create_job(self):
test_job = Job(self.method)
test_job.store()
stored = Job.db_record_from_uuid(self.env, test_job.uuid)
stored = Job.db_records_from_uuids(self.env, [test_job.uuid])
self.assertEqual(len(stored), 1)
return stored
5 changes: 3 additions & 2 deletions test_queue_job/tests/test_delay_mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,12 @@ def test_trap_jobs_on_with_delay_assert_model_enqueued_mismatch(self):
"identity_key=<function identity_exact at 0x[0-9a-fA-F]+>, "
"max_retries=1, priority=15\\) was not enqueued\\.\n"
"Actual enqueued jobs:\n"
r" \* <test.queue.job\({record_id},\)>.testing_method\(1, foo=2\) with "
rf" \* <test.queue.job\({recordset.id},\)>.testing_method"
r"\(1, foo=2\) with "
r"properties \(priority=15, max_retries=1, eta=15, description=Test, "
r"channel=root.test, "
r"identity_key=<function identity_exact at 0x[0-9a-fA-F]+>\)"
).format(record_id=recordset.id)
)
with self.assertRaisesRegex(AssertionError, message):
trap.assert_enqueued_job(
self.env["test.queue.job"].testing_method,
Expand Down
18 changes: 12 additions & 6 deletions test_queue_job/tests/test_delayable.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Copyright 2019 Guewen Baconnier
# license lgpl-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

import gc
import logging

import odoo.tests.common as common

from odoo.addons.queue_job.delay import (
Expand Down Expand Up @@ -279,20 +282,23 @@ def test_delayable_group_of_chain(self):
)

def test_log_not_delayed(self):
logger_name = "odoo.addons.queue_job"
with self.assertLogs(logger_name, level="WARN") as test:
with self.assertLogs(level=logging.WARNING) as test:
# When a Delayable never gets a delay() call,
# when the GC collects it and calls __del__, a warning
# will be displayed. We cannot test this is a scenario
# using the GC as it isn't predictable. Call __del__
# directly
# will be displayed.
node = self.job_node(1)
node.__del__()
expected = (
"WARNING:odoo.addons.queue_job.delay:Delayable "
"Delayable(test.queue.job().testing_method((1,), {}))"
" was prepared but never delayed"
)
self.assertFalse(node._generated_job)

# Remove reference
del node
# Collect garbage using gc
gc.collect()

self.assertEqual(test.output, [expected])

def test_delay_job_already_exists(self):
Expand Down
4 changes: 1 addition & 3 deletions test_queue_job/tests/test_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,9 +527,7 @@ def test_button_done(self):
stored = self._create_job()
stored.button_done()
self.assertEqual(stored.state, DONE)
self.assertEqual(
stored.result, "Manually set to done by %s" % self.env.user.name
)
self.assertEqual(stored.result, f"Manually set to done by {self.env.user.name}")

def test_button_done_enqueue_waiting_dependencies(self):
job_root = Job(self.env["test.queue.job"].testing_method)
Expand Down
11 changes: 1 addition & 10 deletions test_queue_job/tests/test_job_auto_delay.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@ def test_auto_delay_inside_job(self):

def test_auto_delay_force_sync(self):
"""method forced to run synchronously"""
with self.assertLogs(level="WARNING") as log_catcher:
result = (
self.env["test.queue.job"]
.with_context(_job_force_sync=True)
.delay_me(1, kwarg=2)
)
self.assertEqual(
len(log_catcher.output), 1, "Exactly one warning should be logged"
)
self.assertIn(" ctx key found. NO JOB scheduled. ", log_catcher.output[0])
result = self.env["test.queue.job"].delay_me(1, kwarg=2)
self.assertTrue(result, (1, 2))

def test_auto_delay_context_key_set(self):
Expand Down
2 changes: 1 addition & 1 deletion test_queue_job/tests/test_job_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

class TestJobFunction(common.TransactionCase):
def setUp(self):
super(TestJobFunction, self).setUp()
super().setUp()
self.test_function_model = self.env.ref(
"queue_job.job_function_queue_job__test_job"
)
Expand Down

0 comments on commit bb4b6f6

Please sign in to comment.