summaryrefslogtreecommitdiff
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-02-20 07:19:39 +0000
committerGerrit Code Review <review@openstack.org>2012-02-20 07:19:39 +0000
commit757d8aa6f5e412aae08c2b1fb2d0c6f174d2f29c (patch)
tree58604d75f0a30360f38e855bbcd67772c5285cc7 /nova/tests
parent6f3751fcbd6a13902d33374d5ef884ad88748048 (diff)
parentc30193fbf5c0f2e77b09a44803246732c10e211d (diff)
downloadnova-757d8aa6f5e412aae08c2b1fb2d0c6f174d2f29c.tar.gz
Merge "Support non-UTC timestamps in changes-since filter"
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py4
-rw-r--r--nova/tests/test_utils.py109
2 files changed, 111 insertions, 2 deletions
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index 97add65b4e..c06fff32dc 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -21,6 +21,7 @@ import json
import urlparse
import uuid
+import iso8601
from lxml import etree
import webob
@@ -889,7 +890,8 @@ class ServersControllerTest(test.TestCase):
def fake_get_all(compute_self, context, search_opts=None):
self.assertNotEqual(search_opts, None)
self.assertTrue('changes-since' in search_opts)
- changes_since = datetime.datetime(2011, 1, 24, 17, 8, 1)
+ changes_since = datetime.datetime(2011, 1, 24, 17, 8, 1,
+ tzinfo=iso8601.iso8601.UTC)
self.assertEqual(search_opts['changes-since'], changes_since)
self.assertTrue('deleted' not in search_opts)
return [fakes.stub_instance(100, uuid=server_uuid)]
diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py
index 5da717bee3..c60dc26a99 100644
--- a/nova/tests/test_utils.py
+++ b/nova/tests/test_utils.py
@@ -15,13 +15,15 @@
# under the License.
import __builtin__
-import mox
import datetime
import hashlib
import os
import StringIO
import tempfile
+import iso8601
+import mox
+
import nova
from nova import exception
from nova import flags
@@ -700,3 +702,108 @@ class DeprecationTest(test.TestCase):
h1 = utils.hash_file(flo)
h2 = hashlib.sha1(data).hexdigest()
self.assertEquals(h1, h2)
+
+
+class Iso8601TimeTest(test.TestCase):
+
+ def _instaneous(self, timestamp, yr, mon, day, hr, min, sec, micro):
+ self.assertEquals(timestamp.year, yr)
+ self.assertEquals(timestamp.month, mon)
+ self.assertEquals(timestamp.day, day)
+ self.assertEquals(timestamp.hour, hr)
+ self.assertEquals(timestamp.minute, min)
+ self.assertEquals(timestamp.second, sec)
+ self.assertEquals(timestamp.microsecond, micro)
+
+ def _do_test(self, str, yr, mon, day, hr, min, sec, micro, shift):
+ DAY_SECONDS = 24 * 60 * 60
+ timestamp = utils.parse_isotime(str)
+ self._instaneous(timestamp, yr, mon, day, hr, min, sec, micro)
+ offset = timestamp.tzinfo.utcoffset(None)
+ self.assertEqual(offset.seconds + offset.days * DAY_SECONDS, shift)
+
+ def test_zulu(self):
+ str = '2012-02-14T20:53:07Z'
+ self._do_test(str, 2012, 02, 14, 20, 53, 7, 0, 0)
+
+ def test_zulu_micros(self):
+ str = '2012-02-14T20:53:07.123Z'
+ self._do_test(str, 2012, 02, 14, 20, 53, 7, 123000, 0)
+
+ def test_offset_east(self):
+ str = '2012-02-14T20:53:07+04:30'
+ offset = 4.5 * 60 * 60
+ self._do_test(str, 2012, 02, 14, 20, 53, 7, 0, offset)
+
+ def test_offset_east_micros(self):
+ str = '2012-02-14T20:53:07.42+04:30'
+ offset = 4.5 * 60 * 60
+ self._do_test(str, 2012, 02, 14, 20, 53, 7, 420000, offset)
+
+ def test_offset_west(self):
+ str = '2012-02-14T20:53:07-05:30'
+ offset = -5.5 * 60 * 60
+ self._do_test(str, 2012, 02, 14, 20, 53, 7, 0, offset)
+
+ def test_offset_west_micros(self):
+ str = '2012-02-14T20:53:07.654321-05:30'
+ offset = -5.5 * 60 * 60
+ self._do_test(str, 2012, 02, 14, 20, 53, 7, 654321, offset)
+
+ def test_compare(self):
+ zulu = utils.parse_isotime('2012-02-14T20:53:07')
+ east = utils.parse_isotime('2012-02-14T20:53:07-01:00')
+ west = utils.parse_isotime('2012-02-14T20:53:07+01:00')
+ self.assertTrue(east > west)
+ self.assertTrue(east > zulu)
+ self.assertTrue(zulu > west)
+
+ def test_compare_micros(self):
+ zulu = utils.parse_isotime('2012-02-14T20:53:07.6544')
+ east = utils.parse_isotime('2012-02-14T19:53:07.654321-01:00')
+ west = utils.parse_isotime('2012-02-14T21:53:07.655+01:00')
+ self.assertTrue(east < west)
+ self.assertTrue(east < zulu)
+ self.assertTrue(zulu < west)
+
+ def test_zulu_roundtrip(self):
+ str = '2012-02-14T20:53:07Z'
+ zulu = utils.parse_isotime(str)
+ self.assertEquals(zulu.tzinfo, iso8601.iso8601.UTC)
+ self.assertEquals(utils.isotime(zulu), str)
+
+ def test_east_roundtrip(self):
+ str = '2012-02-14T20:53:07-07:00'
+ east = utils.parse_isotime(str)
+ self.assertEquals(east.tzinfo.tzname(None), '-07:00')
+ self.assertEquals(utils.isotime(east), str)
+
+ def test_west_roundtrip(self):
+ str = '2012-02-14T20:53:07+11:30'
+ west = utils.parse_isotime(str)
+ self.assertEquals(west.tzinfo.tzname(None), '+11:30')
+ self.assertEquals(utils.isotime(west), str)
+
+ def test_now_roundtrip(self):
+ str = utils.isotime()
+ now = utils.parse_isotime(str)
+ self.assertEquals(now.tzinfo, iso8601.iso8601.UTC)
+ self.assertEquals(utils.isotime(now), str)
+
+ def test_zulu_normalize(self):
+ str = '2012-02-14T20:53:07Z'
+ zulu = utils.parse_isotime(str)
+ normed = utils.normalize_time(zulu)
+ self._instaneous(normed, 2012, 2, 14, 20, 53, 07, 0)
+
+ def test_east_normalize(self):
+ str = '2012-02-14T20:53:07-07:00'
+ east = utils.parse_isotime(str)
+ normed = utils.normalize_time(east)
+ self._instaneous(normed, 2012, 2, 15, 03, 53, 07, 0)
+
+ def test_west_normalize(self):
+ str = '2012-02-14T20:53:07+21:00'
+ west = utils.parse_isotime(str)
+ normed = utils.normalize_time(west)
+ self._instaneous(normed, 2012, 2, 13, 23, 53, 07, 0)