summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorMonsyne Dragon <mdragon@rackspace.com>2012-03-07 00:49:57 +0000
committerMonsyne Dragon <mdragon@rackspace.com>2012-03-07 16:32:47 +0000
commit6de3fe69f64fd0c304ee3f8e4bdcafada0d48117 (patch)
tree133a10ea4da550d60d78b836a7c9735d30644957 /nova/tests
parentd8324bb3d089acd444bd1639a3efc07e89556f69 (diff)
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
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_utils.py164
1 files changed, 164 insertions, 0 deletions
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))