1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
import datetime
import pytz
import tzlocal
from caldav.elements.cdav import _to_utc_date_string
from caldav.elements.cdav import CalendarQuery
SOMEWHERE_REMOTE = pytz.timezone("Brazil/DeNoronha") # UTC-2 and no DST
def test_element():
cq = CalendarQuery()
assert str(cq).startswith("<?xml")
assert not "xml" in repr(cq)
assert "CalendarQuery" in repr(cq)
assert "calendar-query" in str(cq)
def test_to_utc_date_string_date():
input = datetime.date(2019, 5, 14)
res = _to_utc_date_string(input)
assert res == "20190514T000000Z"
def test_to_utc_date_string_utc():
input = datetime.datetime(2019, 5, 14, 21, 10, 23, 23, tzinfo=datetime.timezone.utc)
try:
res = _to_utc_date_string(input.astimezone())
except:
## old python does not support astimezone() without a parameter given
res = _to_utc_date_string(input.astimezone(tzlocal.get_localzone()))
assert res == "20190514T211023Z"
def test_to_utc_date_string_dt_with_pytz_tzinfo():
input = datetime.datetime(2019, 5, 14, 21, 10, 23, 23)
res = _to_utc_date_string(SOMEWHERE_REMOTE.localize(input))
assert res == "20190514T231023Z"
def test_to_utc_date_string_dt_with_local_tz():
input = datetime.datetime(2019, 5, 14, 21, 10, 23, 23)
try:
res = _to_utc_date_string(input.astimezone())
except:
res = _to_utc_date_string(tzlocal.get_localzone())
exp_dt = datetime.datetime(
2019, 5, 14, 21, 10, 23, 23, tzinfo=tzlocal.get_localzone()
).astimezone(datetime.timezone.utc)
exp = exp_dt.strftime("%Y%m%dT%H%M%SZ")
assert res == exp
def test_to_utc_date_string_naive_dt():
input = datetime.datetime(2019, 5, 14, 21, 10, 23, 23)
res = _to_utc_date_string(input)
exp_dt = datetime.datetime(
2019, 5, 14, 21, 10, 23, 23, tzinfo=tzlocal.get_localzone()
).astimezone(datetime.timezone.utc)
exp = exp_dt.strftime("%Y%m%dT%H%M%SZ")
assert res == exp
class TestErrorUnitTestBot:
# This test has been generated by UnitTestBot (utbot.org)
def test_to_utc_date_string_with_exception(self):
"""
ts = datetime.datetime(1, 1, 1)
"""
# This test fails because function [caldav.elements.cdav._to_utc_date_string] produces [OverflowError]
_to_utc_date_string(datetime.datetime(1, 1, 1))
class TestRegressionUnitTestBot:
def test_to_utc_date_string_min(self):
input_datetime = datetime.datetime(1, 1, 1)
res = _to_utc_date_string(input_datetime)
exp_dt = datetime.datetime(1, 1, 1, tzinfo=datetime.timezone.utc)
exp = exp_dt.strftime("%Y%m%dT%H%M%SZ")
assert res == exp
|