python 2.6 safe total_seconds

This commit is contained in:
Chris Meyers
2015-07-30 13:40:31 -04:00
parent b0f55c832d
commit f64a48a98f
3 changed files with 17 additions and 7 deletions

View File

@@ -16,6 +16,13 @@ from awx.fact.tests.base import BaseFactTest, FactScanBuilder, TEST_FACT_PACKAGE
__all__ = ['FactHostTest', 'FactTest', 'FactGetHostVersionTest', 'FactGetHostTimelineTest']
# damn you python 2.6
def timedelta_total_seconds(timedelta):
return (
timedelta.microseconds + 0.0 +
(timedelta.seconds + timedelta.days * 24 * 3600) * 10 ** 6) / 10 ** 6
class FactHostTest(BaseFactTest):
def test_create_host(self):
host = FactHost(hostname='hosty', inventory_id=1)
@@ -72,7 +79,7 @@ class FactTest(BaseFactTest):
t1 = now()
(f_obj, v_obj) = Fact.add_fact(host=host, timestamp=timestamp, module='packages', fact=data)
t2 = now()
diff = (t2 - t1).total_seconds()
diff = timedelta_total_seconds(t2 - t1)
print("add_fact save time: %s (s)" % diff)
# Note: 20 is realllly high. This should complete in < 2 seconds
self.assertLessEqual(diff, 20)