2015-06-30 22:33:43 +00:00
|
|
|
import datetime
|
2020-03-01 17:42:29 +00:00
|
|
|
|
|
|
|
from dateutil import tz
|
|
|
|
from docker_custodian import args
|
|
|
|
|
2015-06-30 22:33:43 +00:00
|
|
|
try:
|
|
|
|
from unittest import mock
|
|
|
|
except ImportError:
|
|
|
|
import mock
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_datetime_seconds_ago(now):
|
|
|
|
expected = datetime.datetime(2014, 1, 15, 10, 10, tzinfo=tz.tzutc())
|
|
|
|
with mock.patch(
|
|
|
|
'docker_custodian.args.datetime.datetime',
|
|
|
|
autospec=True,
|
|
|
|
) as mock_datetime:
|
|
|
|
mock_datetime.now.return_value = now
|
|
|
|
assert args.datetime_seconds_ago(24 * 60 * 60 * 5) == expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_timedelta_type_none():
|
|
|
|
assert args.timedelta_type(None) is None
|
|
|
|
|
|
|
|
|
|
|
|
def test_timedelta_type(now):
|
|
|
|
expected = datetime.datetime(2014, 1, 15, 10, 10, tzinfo=tz.tzutc())
|
|
|
|
with mock.patch(
|
|
|
|
'docker_custodian.args.datetime.datetime',
|
|
|
|
autospec=True,
|
|
|
|
) as mock_datetime:
|
|
|
|
mock_datetime.now.return_value = now
|
|
|
|
assert args.timedelta_type('5 days') == expected
|