Merge "api: use delta_seconds()"

This commit is contained in:
Jenkins 2013-02-14 01:21:58 +00:00 committed by Gerrit Code Review
commit 6d70a85850
5 changed files with 12 additions and 19 deletions

View File

@ -324,12 +324,8 @@ class Statistics(Base):
if (self.duration_start and
self.duration_end and
self.duration_start <= self.duration_end):
# Can't use timedelta.total_seconds() because
# it is not available in Python 2.6.
diff = self.duration_end - self.duration_start
self.duration = (diff.seconds + (diff.days * 24 * 60 ** 2)) / 60
# FIXME(dhellmann): Shouldn't this value be returned in
# seconds, or something even smaller?
self.duration = timeutils.delta_seconds(self.duration_start,
self.duration_end)
else:
self.duration_start = self.duration_end = self.duration = None

View File

@ -570,10 +570,7 @@ def compute_duration_by_resource(resource, meter):
# sentinal indicating that there is something "funny"
# about the range.
if min_ts and max_ts and (min_ts <= max_ts):
# Can't use timedelta.total_seconds() because
# it is not available in Python 2.6.
diff = max_ts - min_ts
duration = (diff.seconds + (diff.days * 24 * 60 ** 2)) / 60
duration = timeutils.delta_seconds(min_ts, max_ts)
else:
min_ts = max_ts = duration = None

View File

@ -80,14 +80,14 @@ class TestComputeDurationByResource(tests_api.TestBase):
data = self._invoke_api()
self._assert_times_match(data['start_timestamp'], self.start)
self._assert_times_match(data['end_timestamp'], self.middle1)
assert data['duration'] == 8 * 60
self.assertEqual(data['duration'], 8 * 60 * 60)
def test_within_range(self):
self._set_interval(self.middle1, self.middle2)
data = self._invoke_api()
self._assert_times_match(data['start_timestamp'], self.middle1)
self._assert_times_match(data['end_timestamp'], self.middle2)
assert data['duration'] == 10 * 60
self.assertEqual(data['duration'], 10 * 60 * 60)
def test_within_range_zero_duration(self):
self._set_interval(self.middle1, self.middle1)
@ -101,7 +101,7 @@ class TestComputeDurationByResource(tests_api.TestBase):
data = self._invoke_api()
self._assert_times_match(data['start_timestamp'], self.middle2)
self._assert_times_match(data['end_timestamp'], self.end)
assert data['duration'] == (6 * 60) - 1
self.assertEqual(data['duration'], ((6 * 60) - 1) * 60)
def test_after_range(self):
self._set_interval(self.late1, self.late2)

View File

@ -99,14 +99,14 @@ class TestComputeDurationByResource(FunctionalTest):
data = self._invoke_api()
self._assert_times_match(data['duration_start'], self.start)
self._assert_times_match(data['duration_end'], self.middle1)
assert data['duration'] == 8 * 60
self.assertEqual(data['duration'], 8 * 60 * 60)
def test_within_range(self):
self._set_interval(self.middle1, self.middle2)
data = self._invoke_api()
self._assert_times_match(data['duration_start'], self.middle1)
self._assert_times_match(data['duration_end'], self.middle2)
assert data['duration'] == 10 * 60
self.assertEqual(data['duration'], 10 * 60 * 60)
def test_within_range_zero_duration(self):
self._set_interval(self.middle1, self.middle1)
@ -120,7 +120,7 @@ class TestComputeDurationByResource(FunctionalTest):
data = self._invoke_api()
self._assert_times_match(data['duration_start'], self.middle2)
self._assert_times_match(data['duration_end'], self.end)
assert data['duration'] == (6 * 60) - 1
self.assertEqual(data['duration'], ((6 * 60) - 1) * 60)
def test_after_range(self):
self._set_interval(self.late1, self.late2)

View File

@ -66,7 +66,7 @@ class TestStatisticsDuration(unittest.TestCase):
)
assert s.duration_start == self.start
assert s.duration_end == self.middle1
assert s.duration == 8 * 60
self.assertEqual(s.duration, 8 * 60 * 60)
def test_within_range(self):
s = v2.Statistics(duration_start=self.middle1,
@ -76,7 +76,7 @@ class TestStatisticsDuration(unittest.TestCase):
)
assert s.duration_start == self.middle1
assert s.duration_end == self.middle2
assert s.duration == 10 * 60
self.assertEqual(s.duration, 10 * 60 * 60)
def test_within_range_zero_duration(self):
s = v2.Statistics(duration_start=self.middle1,
@ -96,7 +96,7 @@ class TestStatisticsDuration(unittest.TestCase):
)
assert s.duration_start == self.middle2
assert s.duration_end == self.end
assert s.duration == (6 * 60) - 1
self.assertEqual(s.duration, ((6 * 60) - 1) * 60)
def test_after_range(self):
s = v2.Statistics(duration_start=self.late1,