Example #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
Example #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
Example #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)
Example #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())
Example #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())
Example #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)
Example #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())
Example #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)
Example #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
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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())
Example #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)
Example #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())
Example #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)
Example #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())