summaryrefslogtreecommitdiffstats
path: root/nova/tests
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2012-06-13 20:40:48 +0000
committerGerrit Code Review <review@openstack.org>2012-06-13 20:40:48 +0000
commitcb8a51bbe63f2b4b1aa0e108f74bb6092c3898eb (patch)
treeeeb82b9bf27530cd4ef695aaabe21b600a575f5b /nova/tests
parent9e0c6845562dcd8e294841ac06aad559247de0cf (diff)
parent294dd459827c3d79ae684f9f206bcc213c69dd12 (diff)
Merge "Remove utils.deprecated functions."
Diffstat (limited to 'nova/tests')
-rw-r--r--nova/tests/test_utils.py200
1 files changed, 45 insertions, 155 deletions
diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py
index f990a6730..6b83802e4 100644
--- a/nova/tests/test_utils.py
+++ b/nova/tests/test_utils.py
@@ -416,6 +416,51 @@ class GenericUtilsTestCase(test.TestCase):
self.assertEqual(fake_execute.uid, 2)
self.assertEqual(fake_execute.uid, os.getuid())
+ def test_service_is_up(self):
+ fts_func = datetime.datetime.fromtimestamp
+ fake_now = 1000
+ down_time = 5
+
+ self.flags(service_down_time=down_time)
+ self.mox.StubOutWithMock(utils, 'utcnow')
+
+ # Up (equal)
+ utils.utcnow().AndReturn(fts_func(fake_now))
+ service = {'updated_at': fts_func(fake_now - down_time),
+ 'created_at': fts_func(fake_now - down_time)}
+ self.mox.ReplayAll()
+ result = utils.service_is_up(service)
+ self.assertTrue(result)
+
+ self.mox.ResetAll()
+ # Up
+ utils.utcnow().AndReturn(fts_func(fake_now))
+ service = {'updated_at': fts_func(fake_now - down_time + 1),
+ 'created_at': fts_func(fake_now - down_time + 1)}
+ self.mox.ReplayAll()
+ result = utils.service_is_up(service)
+ self.assertTrue(result)
+
+ self.mox.ResetAll()
+ # Down
+ utils.utcnow().AndReturn(fts_func(fake_now))
+ service = {'updated_at': fts_func(fake_now - down_time - 1),
+ 'created_at': fts_func(fake_now - down_time - 1)}
+ self.mox.ReplayAll()
+ result = utils.service_is_up(service)
+ self.assertFalse(result)
+
+ def test_xhtml_escape(self):
+ self.assertEqual('&quot;foo&quot;', utils.xhtml_escape('"foo"'))
+ self.assertEqual('&apos;foo&apos;', utils.xhtml_escape("'foo'"))
+
+ def test_hash_file(self):
+ data = 'Mary had a little lamb, its fleece as white as snow'
+ flo = StringIO.StringIO(data)
+ h1 = utils.hash_file(flo)
+ h2 = hashlib.sha1(data).hexdigest()
+ self.assertEquals(h1, h2)
+
class IsUUIDLikeTestCase(test.TestCase):
def assertUUIDLike(self, val, expected):
@@ -487,161 +532,6 @@ class MonkeyPatchTestCase(test.TestCase):
in nova.tests.monkey_patch_example.CALLED_FUNCTION)
-class DeprecationTest(test.TestCase):
- def setUp(self):
- super(DeprecationTest, self).setUp()
-
- def fake_warn_deprecated_class(cls, msg):
- self.warn = ('class', cls, msg)
-
- def fake_warn_deprecated_function(func, msg):
- self.warn = ('function', func, msg)
-
- self.stubs.Set(utils, 'warn_deprecated_class',
- fake_warn_deprecated_class)
- self.stubs.Set(utils, 'warn_deprecated_function',
- fake_warn_deprecated_function)
- self.warn = None
-
- def test_deprecated_function_no_message(self):
- def test_function():
- pass
-
- decorated = utils.deprecated()(test_function)
-
- decorated()
- self.assertEqual(self.warn, ('function', test_function, ''))
-
- def test_deprecated_function_with_message(self):
- def test_function():
- pass
-
- decorated = utils.deprecated('string')(test_function)
-
- decorated()
- self.assertEqual(self.warn, ('function', test_function, 'string'))
-
- def test_deprecated_class_no_message(self):
- @utils.deprecated()
- class TestClass(object):
- pass
-
- TestClass()
- self.assertEqual(self.warn, ('class', TestClass, ''))
-
- def test_deprecated_class_with_message(self):
- @utils.deprecated('string')
- class TestClass(object):
- pass
-
- TestClass()
- self.assertEqual(self.warn, ('class', TestClass, 'string'))
-
- def test_deprecated_classmethod_no_message(self):
- @utils.deprecated()
- class TestClass(object):
- @classmethod
- def class_method(cls):
- pass
-
- TestClass.class_method()
- self.assertEqual(self.warn, ('class', TestClass, ''))
-
- def test_deprecated_classmethod_with_message(self):
- @utils.deprecated('string')
- class TestClass(object):
- @classmethod
- def class_method(cls):
- pass
-
- TestClass.class_method()
- self.assertEqual(self.warn, ('class', TestClass, 'string'))
-
- def test_deprecated_staticmethod_no_message(self):
- @utils.deprecated()
- class TestClass(object):
- @staticmethod
- def static_method():
- pass
-
- TestClass.static_method()
- self.assertEqual(self.warn, ('class', TestClass, ''))
-
- def test_deprecated_staticmethod_with_message(self):
- @utils.deprecated('string')
- class TestClass(object):
- @staticmethod
- def static_method():
- pass
-
- TestClass.static_method()
- self.assertEqual(self.warn, ('class', TestClass, 'string'))
-
- def test_deprecated_instancemethod(self):
- @utils.deprecated()
- class TestClass(object):
- def instance_method(self):
- pass
-
- # Instantiate the class...
- obj = TestClass()
- self.assertEqual(self.warn, ('class', TestClass, ''))
-
- # Reset warn...
- self.warn = None
-
- # Call the instance method...
- obj.instance_method()
-
- # Make sure that did *not* generate a warning
- self.assertEqual(self.warn, None)
-
- def test_service_is_up(self):
- fts_func = datetime.datetime.fromtimestamp
- fake_now = 1000
- down_time = 5
-
- self.flags(service_down_time=down_time)
- self.mox.StubOutWithMock(utils, 'utcnow')
-
- # Up (equal)
- utils.utcnow().AndReturn(fts_func(fake_now))
- service = {'updated_at': fts_func(fake_now - down_time),
- 'created_at': fts_func(fake_now - down_time)}
- self.mox.ReplayAll()
- result = utils.service_is_up(service)
- self.assertTrue(result)
-
- self.mox.ResetAll()
- # Up
- utils.utcnow().AndReturn(fts_func(fake_now))
- service = {'updated_at': fts_func(fake_now - down_time + 1),
- 'created_at': fts_func(fake_now - down_time + 1)}
- self.mox.ReplayAll()
- result = utils.service_is_up(service)
- self.assertTrue(result)
-
- self.mox.ResetAll()
- # Down
- utils.utcnow().AndReturn(fts_func(fake_now))
- service = {'updated_at': fts_func(fake_now - down_time - 1),
- 'created_at': fts_func(fake_now - down_time - 1)}
- self.mox.ReplayAll()
- result = utils.service_is_up(service)
- self.assertFalse(result)
-
- def test_xhtml_escape(self):
- self.assertEqual('&quot;foo&quot;', utils.xhtml_escape('"foo"'))
- self.assertEqual('&apos;foo&apos;', utils.xhtml_escape("'foo'"))
-
- def test_hash_file(self):
- data = 'Mary had a little lamb, its fleece as white as snow'
- flo = StringIO.StringIO(data)
- 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):