def test_serialization(self, mock): dt = datetime(2012, 10, 24, 10, 20, tzinfo=dateutils.utc_tz()) last_updated = dateutils.datetime_to_utc_timestamp(dt) unit = {'_last_updated': last_updated} serialized = content.content_unit_obj(unit) mock.assert_called_once_with(unit) self.assertTrue(LAST_UPDATED in serialized) self.assertEqual(serialized[LAST_UPDATED], '2012-10-24T10:20:00Z')
def get_expiration(duration): """ Get an expiration timestamp using the specified duration in seconds. :param duration: The duration in seconds. :type duration: int :return: The timestamp. :rtype: int """ now = datetime.now(dateutils.utc_tz()) dt = now + timedelta(seconds=duration) return dateutils.datetime_to_utc_timestamp(dt)
def purge_archived_tasks(): """ Remove archived tasks from the database that have expired. """ archived_call_lifetime = pulp_config.config.getint('tasks', 'archived_call_lifetime') delta = datetime.timedelta(hours=archived_call_lifetime) now = datetime.datetime.now(tz=dateutils.utc_tz()) expired_timestamp = dateutils.datetime_to_utc_timestamp(now - delta) collection = ArchivedCall.get_collection() collection.remove({'timestamp': {'$lte': expired_timestamp}}, safe=True)
def test_formatting_utc_timestamp(self): dt = datetime.datetime(2012, 10, 24, 10, 20, tzinfo=dateutils.utc_tz()) ts = dateutils.datetime_to_utc_timestamp(dt) formatted = dateutils.format_iso8601_utc_timestamp(ts) self.assertEqual(formatted, '2012-10-24T10:20:00Z')