Skip to content

Commit 6f39e2c

Browse files
committed
[MIG] endpoint_cache_preheat: Migration to 18.0
1 parent 58b8c75 commit 6f39e2c

File tree

4 files changed

+28
-22
lines changed

4 files changed

+28
-22
lines changed

endpoint_cache_preheat/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Endpoint cache pre-heat",
66
"summary": """Provide basic pre-caching features for endpoints""",
7-
"version": "14.0.1.0.0",
7+
"version": "18.0.1.0.0",
88
"license": "LGPL-3",
99
"development_status": "Alpha",
1010
"author": "Camptocamp, Odoo Community Association (OCA)",

endpoint_cache_preheat/data/cron.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
<field name="user_id" ref="base.user_root" />
77
<field name="interval_number">1</field>
88
<field name="interval_type">days</field>
9-
<field name="numbercall">-1</field>
109
<field
1110
name="nextcall"
1211
eval="(datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00')"
1312
/>
14-
<field name="doall" eval="False" />
1513
<field name="model_id" ref="endpoint.model_endpoint_endpoint" />
1614
<field name="state">code</field>
1715
<field name="code">model.cron_endpoint_cache_preheat()</field>

endpoint_cache_preheat/models/endpoint_mixin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def _cron_endpoint_cache_preheat(self):
5656
self.cache_preheat_ts = fields.Datetime.now()
5757

5858
def _endpoint_cache_wipe(self, domain):
59+
# pylint: disable=missing-return
5960
super()._endpoint_cache_wipe(domain)
6061
self.cache_preheat_ts = False
6162

endpoint_cache_preheat/tests/test_endpoint.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
44

55
import textwrap
6+
from datetime import datetime
67

8+
from dateutil.relativedelta import relativedelta
79
from freezegun import freeze_time
810

911
from odoo import fields
@@ -16,6 +18,7 @@
1618
class TestEndpoint(CommonEndpoint):
1719
@classmethod
1820
def _setup_records(cls):
21+
# pylint: disable=missing-return
1922
super()._setup_records()
2023
cls.endpoint1 = cls.env.ref("endpoint.endpoint_demo_1")
2124
cls.cron = cls.env.ref("endpoint_cache_preheat.cron_endpoint_cache_preheat")
@@ -27,7 +30,7 @@ def _run_cron(self):
2730
def test_cron_preheat_cache(self):
2831
self.assertFalse(self.endpoint1.cache_preheat)
2932
self.assertFalse(self.endpoint1.cache_preheat_ts)
30-
now = fields.Datetime.from_string("2025-02-19 23:00:00")
33+
now = datetime.now().replace(microsecond=0)
3134
ep_daily = self.endpoint1.copy({"route": "/daily"})
3235
ep_daily.cache_preheat = True
3336
ep_daily.cache_preheat_ts = now
@@ -46,14 +49,15 @@ def test_cron_preheat_cache(self):
4649
)
4750
ep_weekly = ep_daily.copy({"route": "/weekly", "cache_policy": "week"})
4851
ep_monthly = ep_daily.copy({"route": "/monthly", "cache_policy": "month"})
52+
4953
# 1 day later
50-
future_date = fields.Datetime.from_string("2025-02-20 20:00:00")
51-
with trap_jobs() as trap, freeze_time(future_date), MockRequest(self.env):
54+
future_date_1 = now + relativedelta(days=1)
55+
with trap_jobs() as trap, freeze_time(future_date_1), MockRequest(self.env):
5256
self._run_cron()
5357
trap.assert_jobs_count(1)
5458
trap.assert_enqueued_job(ep_daily._cron_endpoint_cache_preheat)
5559
trap.perform_enqueued_jobs()
56-
self.assertEqual(ep_daily.cache_preheat_ts, future_date)
60+
self.assertEqual(ep_daily.cache_preheat_ts, future_date_1)
5761
self.assertEqual(ep_weekly.cache_preheat_ts, now)
5862
self.assertEqual(ep_monthly.cache_preheat_ts, now)
5963

@@ -75,22 +79,23 @@ def test_cron_preheat_cache(self):
7579
),
7680
0,
7781
)
82+
7883
# 2 days later
79-
future_date = fields.Datetime.from_string("2025-02-21 21:30:00")
80-
with trap_jobs() as trap, freeze_time(future_date), MockRequest(self.env):
84+
future_date_2 = now + relativedelta(days=2)
85+
with trap_jobs() as trap, freeze_time(future_date_2), MockRequest(self.env):
8186
self._run_cron()
8287
trap.assert_jobs_count(1)
8388
trap.assert_enqueued_job(ep_daily._cron_endpoint_cache_preheat)
8489
trap.perform_enqueued_jobs()
85-
self.assertEqual(ep_daily.cache_preheat_ts, future_date)
90+
self.assertEqual(ep_daily.cache_preheat_ts, future_date_2)
8691
self.assertEqual(ep_weekly.cache_preheat_ts, now)
8792
self.assertEqual(ep_monthly.cache_preheat_ts, now)
8893

8994
self.assertEqual(
9095
self.env["ir.attachment"].search_count(
9196
ep_daily._endpoint_view_cache_domain()
9297
),
93-
1,
98+
2,
9499
)
95100
self.assertEqual(
96101
self.env["ir.attachment"].search_count(
@@ -104,22 +109,23 @@ def test_cron_preheat_cache(self):
104109
),
105110
0,
106111
)
112+
107113
# 1 week later
108-
future_date = fields.Datetime.from_string("2025-02-26 19:45:00")
109-
with trap_jobs() as trap, freeze_time(future_date), MockRequest(self.env):
114+
future_date_3 = now + relativedelta(weeks=1)
115+
with trap_jobs() as trap, freeze_time(future_date_3), MockRequest(self.env):
110116
self._run_cron()
111117
trap.assert_jobs_count(2)
112118
trap.assert_enqueued_job(ep_daily._cron_endpoint_cache_preheat)
113119
trap.perform_enqueued_jobs()
114-
self.assertEqual(ep_daily.cache_preheat_ts, future_date)
115-
self.assertEqual(ep_weekly.cache_preheat_ts, future_date)
120+
self.assertEqual(ep_daily.cache_preheat_ts, future_date_3)
121+
self.assertEqual(ep_weekly.cache_preheat_ts, future_date_3)
116122
self.assertEqual(ep_monthly.cache_preheat_ts, now)
117123

118124
self.assertEqual(
119125
self.env["ir.attachment"].search_count(
120126
ep_daily._endpoint_view_cache_domain()
121127
),
122-
2,
128+
3,
123129
)
124130
self.assertEqual(
125131
self.env["ir.attachment"].search_count(
@@ -133,22 +139,23 @@ def test_cron_preheat_cache(self):
133139
),
134140
0,
135141
)
142+
136143
# 1 month later
137-
future_date = fields.Datetime.from_string("2025-03-19 23:45:00")
138-
with trap_jobs() as trap, freeze_time(future_date), MockRequest(self.env):
144+
future_date_4 = now + relativedelta(months=1)
145+
with trap_jobs() as trap, freeze_time(future_date_4), MockRequest(self.env):
139146
self._run_cron()
140147
trap.assert_jobs_count(3)
141148
trap.assert_enqueued_job(ep_daily._cron_endpoint_cache_preheat)
142149
trap.perform_enqueued_jobs()
143-
self.assertEqual(ep_daily.cache_preheat_ts, future_date)
144-
self.assertEqual(ep_weekly.cache_preheat_ts, future_date)
145-
self.assertEqual(ep_monthly.cache_preheat_ts, future_date)
150+
self.assertEqual(ep_daily.cache_preheat_ts, future_date_4)
151+
self.assertEqual(ep_weekly.cache_preheat_ts, future_date_4)
152+
self.assertEqual(ep_monthly.cache_preheat_ts, future_date_4)
146153

147154
self.assertEqual(
148155
self.env["ir.attachment"].search_count(
149156
ep_daily._endpoint_view_cache_domain()
150157
),
151-
3,
158+
4,
152159
)
153160
self.assertEqual(
154161
self.env["ir.attachment"].search_count(

0 commit comments

Comments
 (0)