# Trash arguments validation
trash_at = None
if args.trash_at is not None:
+ # ciso8601 considers YYYYMM as invalid but YYYY-MM as valid, so here we
+ # make sure the user provides a complete YYYY-MM-DD date.
+ if not re.match(r'^\d{4}(?P<dash>-?)\d{2}?(?P=dash)\d{2}', args.trash_at):
+ logger.error("--trash-at argument format invalid, use --help to see examples.")
+ sys.exit(1)
+ # Check if no time information was provided. In that case, assume end-of-day.
+ if re.match(r'^\d{4}(?P<dash>-?)\d{2}?(?P=dash)\d{2}$', args.trash_at):
+ args.trash_at += 'T23:59:59'
try:
trash_at = ciso8601.parse_datetime(args.trash_at)
except:
else:
if trash_at.tzinfo is not None:
# Timezone aware datetime provided.
- utcoffset = trash_at.utcoffset()
+ utcoffset = -trash_at.utcoffset()
else:
# Timezone naive datetime provided. Assume is local.
- utcoffset = datetime.timedelta(hours=-time.timezone/3600)
+ utcoffset = datetime.timedelta(seconds=time.timezone)
# Convert to UTC timezone naive datetime.
- trash_at = trash_at.replace(tzinfo=None) - utcoffset
+ trash_at = trash_at.replace(tzinfo=None) + utcoffset
if trash_at <= datetime.datetime.utcnow():
- logger.error("--trash-at argument should be set in the future")
+ logger.error("--trash-at argument must be set in the future")
sys.exit(1)
if args.trash_after is not None:
if args.trash_after < 1:
- logger.error("--trash-after argument should be >= 1")
+ logger.error("--trash-after argument must be >= 1")
sys.exit(1)
trash_at = datetime.timedelta(seconds=(args.trash_after * 24 * 60 * 60))
self.assertNotEqual(None, col['uuid'])
c = arv_put.api_client.collections().get(uuid=col['uuid']).execute()
self.assertEqual(
- ciso8601.parse_datetime(trash_at).replace(tzinfo=None)+datetime.timedelta(hours=3),
+ ciso8601.parse_datetime(trash_at).replace(tzinfo=None) + datetime.timedelta(hours=3),
ciso8601.parse_datetime(c['trash_at']).replace(tzinfo=None))
def test_put_collection_with_timezone_naive_expiring_datetime(self):
self.assertNotEqual(None, col['uuid'])
c = arv_put.api_client.collections().get(uuid=col['uuid']).execute()
self.assertEqual(
- ciso8601.parse_datetime(trash_at) - datetime.timedelta(hours=-time.timezone/3600),
+ ciso8601.parse_datetime(trash_at) + datetime.timedelta(seconds=time.timezone),
ciso8601.parse_datetime(c['trash_at']).replace(tzinfo=None))
- def test_put_collection_with_invalid_absolute_expiring_datetime(self):
+ def test_put_collection_with_timezone_expiring_date_only(self):
tmpdir = self.make_tmpdir()
+ trash_at = '2140-01-01'
+ end_of_day = datetime.timedelta(hours=23, minutes=59, seconds=59)
with open(os.path.join(tmpdir, 'file1'), 'w') as f:
f.write('Relaxing in basins at the end of inlets terminates the endless tests from the box')
- with self.assertRaises(AssertionError):
- self.run_and_find_collection(
- "",
- ['--no-progress', '--trash-at', 'tomorrow at noon', tmpdir])
+ col = self.run_and_find_collection(
+ "",
+ ['--no-progress', '--trash-at', trash_at, tmpdir])
+ self.assertNotEqual(None, col['uuid'])
+ c = arv_put.api_client.collections().get(uuid=col['uuid']).execute()
+ self.assertEqual(
+ ciso8601.parse_datetime(trash_at) + end_of_day + datetime.timedelta(seconds=time.timezone),
+ ciso8601.parse_datetime(c['trash_at']).replace(tzinfo=None))
+
+ def test_put_collection_with_invalid_absolute_expiring_datetimes(self):
+ cases = ['2100', '210010','2100-10', '2100-Oct']
+ tmpdir = self.make_tmpdir()
+ with open(os.path.join(tmpdir, 'file1'), 'w') as f:
+ f.write('Relaxing in basins at the end of inlets terminates the endless tests from the box')
+ for test_datetime in cases:
+ with self.assertRaises(AssertionError):
+ self.run_and_find_collection(
+ "",
+ ['--no-progress', '--trash-at', test_datetime, tmpdir])
def test_put_collection_with_relative_expiring_datetime(self):
expire_after = 7
self.assertTrue(dt_after > trash_at)
def test_put_collection_with_invalid_relative_expiring_datetime(self):
- expire_after = 0 # Should be >= 1
+ expire_after = 0 # Must be >= 1
tmpdir = self.make_tmpdir()
with open(os.path.join(tmpdir, 'file1'), 'w') as f:
f.write('Relaxing in basins at the end of inlets terminates the endless tests from the box')