def assert_last_sync_time(time_in_iso): now = datetime.datetime.now(dateutils.local_tz()) finished = dateutils.parse_iso8601_datetime(time_in_iso) # Compare them within a threshold since they won't be exact difference = now - finished return difference.seconds < 2
def add_result(repo_id, offset): started = datetime.datetime.now(dateutils.local_tz()) completed = started + datetime.timedelta(days=offset) r = RepoSyncResult.expected_result(repo_id, 'foo', 'bar', dateutils.format_iso8601_datetime(started), dateutils.format_iso8601_datetime(completed), 1, 1, 1, '', '', RepoSyncResult.RESULT_SUCCESS) RepoSyncResult.get_collection().save(r, safe=True)
def test_ensure_tz_specified(self): """ If the timezone is specified, the result should be the same. """ dt = datetime.datetime.now(dateutils.local_tz()) new_date = Repository._ensure_tz_specified(dt) self.assertEquals(new_date.tzinfo, dateutils.utc_tz())
def test_tz_specified(self): """ Ensure that if the tz is already specified, it is used. """ dt = datetime.datetime.now(dateutils.local_tz()) new_date = dateutils.ensure_tz(dt) self.assertEquals(new_date.tzinfo, dateutils.utc_tz())
def test_datetime_with_tz(self): n = datetime.datetime.now(dateutils.local_tz()) s = dateutils.format_iso8601_datetime(n) b = dateutils.parse_iso8601_datetime(s) for f in self.dt_fields: self.assertTrue( getattr(n, f) == getattr(b, f), 'Field mismatch: %s' % f)
def add_result(repo_id, dist_id, offset): started = datetime.datetime.now(dateutils.local_tz()) completed = started + datetime.timedelta(days=offset) r = RepoPublishResult.expected_result( repo_id, dist_id, 'bar', dateutils.format_iso8601_datetime(started), dateutils.format_iso8601_datetime(completed), 'test-summary', 'test-details', RepoPublishResult.RESULT_SUCCESS) RepoPublishResult.get_collection().insert(r, safe=True)
def _now_timestamp(): """ @return: timestamp suitable for indicating when a publish completed @rtype: str """ now = datetime.datetime.now(dateutils.local_tz()) now_in_iso_format = dateutils.format_iso8601_datetime(now) return now_in_iso_format
def add_result(repo_id, offset): started = datetime.datetime.now(dateutils.local_tz()) completed = started + datetime.timedelta(days=offset) r = RepoSyncResult.expected_result( repo_id, 'foo', 'bar', dateutils.format_iso8601_datetime(started), dateutils.format_iso8601_datetime(completed), 1, 1, 1, '', '', RepoSyncResult.RESULT_SUCCESS) RepoSyncResult.get_collection().save(r, safe=True)
def test_last_publish(self): # Setup self.publish_manager.publish(self.group_id, self.distributor_id) # Test last_publish = self.publish_manager.last_publish(self.group_id, self.distributor_id) # Verify now = datetime.datetime.now(dateutils.local_tz()) difference = now - last_publish self.assertTrue(difference.seconds < 2)
def cull_history(self, lifetime): ''' Deletes all consumer history entries that are older than the given lifetime. @param lifetime: length in days; history entries older than this many days old are deleted in this call @type lifetime: L{datetime.timedelta} ''' now = datetime.datetime.now(dateutils.local_tz()) limit = dateutils.format_iso8601_datetime(now - lifetime) spec = {'timestamp': {'$lt': limit}} self.collection.remove(spec, safe=False)
def test_last_publish(self): # Setup distributor, instance, config = self.publish_manager._get_distributor_instance_and_config(self.group_id, self.distributor_id) self.publish_manager.publish(self.group_id, self.distributor_id, distributor, instance, config) # Test last_publish = self.publish_manager.last_publish(self.group_id, self.distributor_id) # Verify now = datetime.datetime.now(dateutils.local_tz()) difference = now - last_publish self.assertTrue(difference.seconds < 2)
def test_last_publish(self): # Setup self.publish_manager.publish(self.group_id, self.distributor_id) # Test last_publish = self.publish_manager.last_publish( self.group_id, self.distributor_id) # Verify now = datetime.datetime.now(dateutils.local_tz()) difference = now - last_publish self.assertTrue(difference.seconds < 2)
def add_result(repo_id, dist_id, offset): started = datetime.datetime.now(dateutils.local_tz()) completed = started + datetime.timedelta(days=offset) r = RepoPublishResult.expected_result( repo_id, dist_id, "bar", dateutils.format_iso8601_datetime(started), dateutils.format_iso8601_datetime(completed), "test-summary", "test-details", RepoPublishResult.RESULT_SUCCESS, ) RepoPublishResult.get_collection().insert(r, safe=True)
def unpickle_timezone_information(offset): """ Unpickle timezone information @param offset: timezone utc offset """ utc_tz = dateutils.utc_tz() utc_offset = utc_tz.utcoffset(None) if offset == utc_offset: return utc_tz local_tz = dateutils.local_tz() local_offset = local_tz.utcoffset(None) if offset == local_offset: return local_tz offset_hours = offset.days * 24 offset_minutes = offset.seconds / 60 return isodate.FixedOffset(offset_hours, offset_minutes)
def test_datetime_with_tz(self): n = datetime.datetime.now(dateutils.local_tz()) s = dateutils.format_iso8601_datetime(n) b = dateutils.parse_iso8601_datetime(s) for f in self.dt_fields: self.assertTrue(getattr(n, f) == getattr(b, f), 'Field mismatch: %s' % f)
def test_utc_offset(self): n1 = datetime.datetime.now(dateutils.local_tz()) u1 = dateutils.to_utc_datetime(n1) n2 = n1.replace(tzinfo=None) u2 = u1.replace(tzinfo=None) self.assertTrue(n2 - u2 == dateutils.local_utcoffset_delta())
def test_local_to_utz_tz_conversion(self): n1 = datetime.datetime.now(dateutils.local_tz()) u = dateutils.to_utc_datetime(n1) n2 = dateutils.to_local_datetime(u) self.assertTrue(n1 == n2)
def test_tz_specified(self): dt = datetime.datetime.now(dateutils.local_tz()) new_date = _ensure_tz_specified(dt) self.assertEquals(new_date.tzinfo, dateutils.utc_tz())