Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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)
Esempio n. 4
0
 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())
Esempio n. 5
0
 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())
Esempio n. 6
0
 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)
Esempio n. 7
0
 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())
Esempio n. 8
0
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)
Esempio n. 9
0
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
Esempio n. 10
0
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)
Esempio n. 11
0
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 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)
Esempio n. 13
0
    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)
Esempio n. 14
0
    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)
Esempio n. 15
0
    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)
Esempio n. 16
0
    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)
Esempio n. 17
0
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)
Esempio n. 18
0
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)
Esempio n. 19
0
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)
Esempio n. 20
0
 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)
Esempio n. 21
0
 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())
Esempio n. 22
0
 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)
Esempio n. 23
0
 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())
Esempio n. 24
0
 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)
Esempio n. 25
0
 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())