1
+ from unittest .mock import patch
1
2
import pytest
2
3
3
4
pytest .importorskip ("celery" )
@@ -213,7 +214,7 @@ def test_get_monitor_config_crontab():
213
214
app .conf .timezone = "Europe/Vienna"
214
215
215
216
celery_schedule = crontab (day_of_month = "3" , hour = "12" , minute = "*/10" )
216
- monitor_config = _get_monitor_config (celery_schedule , app )
217
+ monitor_config = _get_monitor_config (celery_schedule , app , "foo" )
217
218
assert monitor_config == {
218
219
"schedule" : {
219
220
"type" : "crontab" ,
@@ -224,13 +225,19 @@ def test_get_monitor_config_crontab():
224
225
assert "unit" not in monitor_config ["schedule" ]
225
226
226
227
227
- def test_get_monitor_config_seconds ():
228
+ @patch ("sentry_sdk.integrations.celery.logger.warning" )
229
+ def test_get_monitor_config_seconds (mock_logger_warning ):
228
230
app = MagicMock ()
229
231
app .conf = MagicMock ()
230
232
app .conf .timezone = "Europe/Vienna"
231
233
232
234
celery_schedule = schedule (run_every = 3 ) # seconds
233
- monitor_config = _get_monitor_config (celery_schedule , app )
235
+ monitor_config = _get_monitor_config (celery_schedule , app , "foo" )
236
+ mock_logger_warning .assert_called_with (
237
+ "Intervals shorter than one minute are not supported by Sentry Crons. Monitor '%s' has an interval of %s seconds. Use the `exclude_beat_tasks` option in the celery integration to exclude it." ,
238
+ "foo" ,
239
+ 3 ,
240
+ )
234
241
assert monitor_config == {}
235
242
236
243
@@ -240,7 +247,7 @@ def test_get_monitor_config_minutes():
240
247
app .conf .timezone = "Europe/Vienna"
241
248
242
249
celery_schedule = schedule (run_every = 60 ) # seconds
243
- monitor_config = _get_monitor_config (celery_schedule , app )
250
+ monitor_config = _get_monitor_config (celery_schedule , app , "foo" )
244
251
assert monitor_config == {
245
252
"schedule" : {
246
253
"type" : "interval" ,
@@ -257,7 +264,7 @@ def test_get_monitor_config_unknown():
257
264
app .conf .timezone = "Europe/Vienna"
258
265
259
266
unknown_celery_schedule = MagicMock ()
260
- monitor_config = _get_monitor_config (unknown_celery_schedule , app )
267
+ monitor_config = _get_monitor_config (unknown_celery_schedule , app , "foo" )
261
268
assert monitor_config == {}
262
269
263
270
@@ -268,7 +275,7 @@ def test_get_monitor_config_default_timezone():
268
275
269
276
celery_schedule = crontab (day_of_month = "3" , hour = "12" , minute = "*/10" )
270
277
271
- monitor_config = _get_monitor_config (celery_schedule , app )
278
+ monitor_config = _get_monitor_config (celery_schedule , app , "foo" )
272
279
273
280
assert monitor_config ["timezone" ] == "UTC"
274
281
0 commit comments