mirror of
https://github.com/tubearchivist/tubearchivist.git
synced 2025-03-14 09:50:12 +00:00
add tests for invalid schedules
This commit is contained in:
parent
3d12fe7b5e
commit
308d5a0a61
0
tubearchivist/task/tests/__init__.py
Normal file
0
tubearchivist/task/tests/__init__.py
Normal file
0
tubearchivist/task/tests/test_src/__init__.py
Normal file
0
tubearchivist/task/tests/test_src/__init__.py
Normal file
68
tubearchivist/task/tests/test_src/test_config_schedule.py
Normal file
68
tubearchivist/task/tests/test_src/test_config_schedule.py
Normal file
@ -0,0 +1,68 @@
|
||||
"""test schedule parsing"""
|
||||
|
||||
# flake8: noqa: E402
|
||||
|
||||
import os
|
||||
|
||||
import django
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||
django.setup()
|
||||
|
||||
import pytest
|
||||
from task.src.config_schedule import CrontabValidator
|
||||
|
||||
INCORRECT_CRONTAB = [
|
||||
"0 0 * * *",
|
||||
"0 0",
|
||||
"0",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_value", INCORRECT_CRONTAB)
|
||||
def test_invalid_len(invalid_value):
|
||||
"""raise error on invalid crontab"""
|
||||
validator = CrontabValidator()
|
||||
with pytest.raises(ValueError, match="three cron schedule fields"):
|
||||
validator.validate_cron(invalid_value)
|
||||
|
||||
|
||||
NONE_INT_MINUTE = [
|
||||
"* * *",
|
||||
"0,30 * *",
|
||||
"0,1,2 * *",
|
||||
"-1 * *",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_value", NONE_INT_MINUTE)
|
||||
def test_none_int_crontabs(invalid_value):
|
||||
"""raise error on invalid crontab"""
|
||||
validator = CrontabValidator()
|
||||
with pytest.raises(ValueError, match="Must be an integer."):
|
||||
validator.validate_cron(invalid_value)
|
||||
|
||||
|
||||
INVALID_MINUTE = ["60 * *", "61 * *"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_value", INVALID_MINUTE)
|
||||
def test_invalid_minute(invalid_value):
|
||||
"""raise error on invalid crontab"""
|
||||
validator = CrontabValidator()
|
||||
with pytest.raises(ValueError, match="Must be between 0 and 59."):
|
||||
validator.validate_cron(invalid_value)
|
||||
|
||||
|
||||
INVALID_CRONTAB = [
|
||||
"0 /1 *",
|
||||
"0 0/1 *",
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("invalid_value", INVALID_CRONTAB)
|
||||
def test_invalid_crontab(invalid_value):
|
||||
"""raise error on invalid crontab"""
|
||||
validator = CrontabValidator()
|
||||
with pytest.raises(ValueError, match="invalid crontab"):
|
||||
validator.validate_cron(invalid_value)
|
Loading…
Reference in New Issue
Block a user