diff --git a/tests/test_rtutil.py b/tests/test_rtutil.py index 18ff59447c488a6b1eff76da794ff5f2f4af9106..6bfd6b763c7cdfab5e7f16e2137571f82a1b8d2f 100644 --- a/tests/test_rtutil.py +++ b/tests/test_rtutil.py @@ -6,6 +6,7 @@ # LICENSE.txt in the repository. import contextlib +import datetime import itertools import logging import re @@ -287,3 +288,34 @@ def test_txn_with_urls_with_fmts(rt): f'<{DEFAULT_RT_URL}{statement_path}>', '[stmt.txt]', ]) + +@pytest.mark.parametrize('arg,exp_num,exp_offset', [ + # These correspond to the different datetime formats available through + # RT's user settings. + ('Mon Mar 1 01:01:01 2021', 1, None), + ('2021-03-02 02:02:02', 2, None), + ('2021-03-03T03:03:03-0500', 3, -18000), + ('Thu, 4 Mar 2021 04:04:04 -0600', 4, -21600), + ('Fri, 5 Mar 2021 05:05:05 GMT', 5, 0), + ('20210306T060606Z', 6, 0), + ('Sun, Mar 7, 2021 07:07:07 AM', 7, None), + ('Sun, Mar 14, 2021 02:14:14 PM', 14, None), +]) +def test_rt_datetime(arg, exp_num, exp_offset): + actual = rtutil.RTDateTime(arg) + assert actual.year == 2021 + assert actual.month == 3 + assert actual.day == exp_num + assert actual.hour == exp_num + assert actual.minute == exp_num + assert actual.second == exp_num + if exp_offset is None: + assert actual.tzinfo is None + else: + assert actual.tzinfo.utcoffset(None).total_seconds() == exp_offset + +@pytest.mark.parametrize('arg', ['Not set', '', None]) +def test_rt_datetime_empty(arg): + actual = rtutil.RTDateTime(arg) + assert actual == datetime.datetime.min + assert actual.tzinfo is None