From 6de3fe69f64fd0c304ee3f8e4bdcafada0d48117 Mon Sep 17 00:00:00 2001 From: Monsyne Dragon Date: Wed, 7 Mar 2012 00:49:57 +0000 Subject: Add adjustable offset to audit_period. Allows audit periods to be offset, so daily periods can begin at local midnight, instead of UTC, monthly periods can begin on the 15th instead of the 1st, etc. Fixes bug 948601 Change-Id: I38f6af0a5a513f888b791a4b9ca39467030105f2 --- nova/tests/test_utils.py | 164 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py index e3457dd2d..15b618d8e 100644 --- a/nova/tests/test_utils.py +++ b/nova/tests/test_utils.py @@ -965,3 +965,167 @@ class TestLockCleanup(test.TestCase): self.assertTrue(os.path.exists(lock3)) os.unlink(lock3) + + +class AuditPeriodTest(test.TestCase): + + def setUp(self): + super(AuditPeriodTest, self).setUp() + #a fairly random time to test with + self.test_time = datetime.datetime(second=23, + minute=12, + hour=8, + day=5, + month=3, + year=2012) + utils.set_time_override(override_time=self.test_time) + + def tearDown(self): + utils.clear_time_override() + super(AuditPeriodTest, self).tearDown() + + def test_hour(self): + begin, end = utils.current_audit_period(unit='hour') + self.assertEquals(begin, datetime.datetime( + hour=7, + day=5, + month=3, + year=2012)) + self.assertEquals(end, datetime.datetime( + hour=8, + day=5, + month=3, + year=2012)) + + def test_hour_with_offset_before_current(self): + begin, end = utils.current_audit_period(unit='hour@10') + self.assertEquals(begin, datetime.datetime( + minute=10, + hour=7, + day=5, + month=3, + year=2012)) + self.assertEquals(end, datetime.datetime( + minute=10, + hour=8, + day=5, + month=3, + year=2012)) + + def test_hour_with_offset_after_current(self): + begin, end = utils.current_audit_period(unit='hour@30') + self.assertEquals(begin, datetime.datetime( + minute=30, + hour=6, + day=5, + month=3, + year=2012)) + self.assertEquals(end, datetime.datetime( + minute=30, + hour=7, + day=5, + month=3, + year=2012)) + + def test_day(self): + begin, end = utils.current_audit_period(unit='day') + self.assertEquals(begin, datetime.datetime( + day=4, + month=3, + year=2012)) + self.assertEquals(end, datetime.datetime( + day=5, + month=3, + year=2012)) + + def test_day_with_offset_before_current(self): + begin, end = utils.current_audit_period(unit='day@6') + self.assertEquals(begin, datetime.datetime( + hour=6, + day=4, + month=3, + year=2012)) + self.assertEquals(end, datetime.datetime( + hour=6, + day=5, + month=3, + year=2012)) + + def test_day_with_offset_after_current(self): + begin, end = utils.current_audit_period(unit='day@10') + self.assertEquals(begin, datetime.datetime( + hour=10, + day=3, + month=3, + year=2012)) + self.assertEquals(end, datetime.datetime( + hour=10, + day=4, + month=3, + year=2012)) + + def test_month(self): + begin, end = utils.current_audit_period(unit='month') + self.assertEquals(begin, datetime.datetime( + day=1, + month=2, + year=2012)) + self.assertEquals(end, datetime.datetime( + day=1, + month=3, + year=2012)) + + def test_month_with_offset_before_current(self): + begin, end = utils.current_audit_period(unit='month@2') + self.assertEquals(begin, datetime.datetime( + day=2, + month=2, + year=2012)) + self.assertEquals(end, datetime.datetime( + day=2, + month=3, + year=2012)) + + def test_month_with_offset_after_current(self): + begin, end = utils.current_audit_period(unit='month@15') + self.assertEquals(begin, datetime.datetime( + day=15, + month=1, + year=2012)) + self.assertEquals(end, datetime.datetime( + day=15, + month=2, + year=2012)) + + def test_year(self): + begin, end = utils.current_audit_period(unit='year') + self.assertEquals(begin, datetime.datetime( + day=1, + month=1, + year=2011)) + self.assertEquals(end, datetime.datetime( + day=1, + month=1, + year=2012)) + + def test_year_with_offset_before_current(self): + begin, end = utils.current_audit_period(unit='year@2') + self.assertEquals(begin, datetime.datetime( + day=1, + month=2, + year=2011)) + self.assertEquals(end, datetime.datetime( + day=1, + month=2, + year=2012)) + + def test_year_with_offset_after_current(self): + begin, end = utils.current_audit_period(unit='year@6') + self.assertEquals(begin, datetime.datetime( + day=1, + month=6, + year=2010)) + self.assertEquals(end, datetime.datetime( + day=1, + month=6, + year=2011)) -- cgit