Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Der-Henning
GitHub Repository: Der-Henning/tgtg
Path: blob/main/tests/test_cron.py
725 views
1
import pytest
2
3
from tgtg_scanner.models.cron import Cron
4
5
6
def test_description():
7
assert Cron().get_description() == "Every minute"
8
assert Cron("0 0 * * *").get_description() == "At 00:00"
9
assert Cron("0 0 * * 0").get_description() == "At 00:00, only on Sunday"
10
assert Cron("0 0 * * 0-1").get_description() == "At 00:00, Sunday through Monday"
11
assert Cron("0 0 * * 0-1").get_description("de_DE") == "Um 00:00, Sunday bis Monday"
12
assert Cron("0 0 * * 0-1").get_description("fr_FR") == "À 00:00, de Sunday à Monday"
13
assert Cron("0 0 * * 0-1").get_description("it_IT") == "Alle 00:00, Sunday al Monday"
14
assert Cron("* * * * 0-6").get_description() == "Every minute, Sunday through Saturday"
15
assert Cron("* * * * 1-5").get_description() == "Every minute, Monday through Friday"
16
assert Cron("* 6-22 * * *").get_description() == "Every minute, between 06:00 and 22:59"
17
assert Cron("* 6-22 * * 1-5; * 19-22 * * 0,6").get_description() == (
18
"Every minute, between 06:00 and 22:59, Monday through Friday; "
19
"Every minute, between 19:00 and 22:59, only on Sunday and Saturday"
20
)
21
with pytest.raises(ValueError):
22
Cron("* * * * 0-7")
23
with pytest.raises(ValueError):
24
Cron("* * * * 7")
25
with pytest.raises(ValueError):
26
Cron("abc")
27
28
29
def test_is_now():
30
assert Cron("* * * * *").is_now is True
31
32
33
def test_eq():
34
assert Cron("0 0 * * *") == Cron("0 0 * * *")
35
assert Cron("0 0 * * *") != Cron("0 0 * * 0")
36
assert Cron() == Cron("* * * * *")
37
assert Cron() == Cron(" * * * * * ")
38
assert Cron("* * * * *; * * * * *") == Cron("* * * * *")
39
40
41
def test_repr():
42
assert repr(Cron("0 0 * * *")) == "Cron(['0 0 * * *'])"
43
44