]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
test_s3: use try_import from common
authorAngus Salkeld <asalkeld@redhat.com>
Wed, 6 Feb 2013 11:25:22 +0000 (22:25 +1100)
committerAngus Salkeld <asalkeld@redhat.com>
Wed, 6 Feb 2013 22:12:29 +0000 (09:12 +1100)
Change-Id: I3055c3d2f8061b91b038286d8ff2c5cbdcd41efd

heat/tests/test_s3.py

index 9d1db47da2b70bbb7221d606074eb1c470c40de5..709b5a512a1bb4a603aa551256e7c527280c5f5a 100644 (file)
@@ -23,22 +23,18 @@ from nose.plugins.attrib import attr
 
 from heat.common import context
 from heat.common import template_format
+from heat.openstack.common.importutils import try_import
 from heat.engine.resources import s3
 from heat.engine import parser
 from utils import skip_if
 
-try:
-    from swiftclient import client as swiftclient
-except ImportError:
-    skip_test = True
-else:
-    skip_test = False
+swiftclient = try_import('swiftclient.client')
 
 
 @attr(tag=['unit', 'resource'])
 @attr(speed='fast')
 class s3Test(unittest.TestCase):
-    @skip_if(skip_test, 'unable to import swiftclient')
+    @skip_if(swiftclient is None, 'unable to import swiftclient')
     def setUp(self):
         self.m = mox.Mox()
         self.m.CreateMock(swiftclient.Connection)
@@ -78,14 +74,14 @@ class s3Test(unittest.TestCase):
         self.assertEqual(s3.S3Bucket.CREATE_COMPLETE, resource.state)
         return resource
 
-    @skip_if(skip_test, 'unable to import swiftclient')
+    @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_create_container_name(self):
         self.m.UnsetStubs()
         self.assertTrue(re.match(self.container_pattern,
                         s3.S3Bucket._create_container_name(
                         'test_stack.test_resource')))
 
-    @skip_if(skip_test, 'unable to import swiftclient')
+    @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_attributes(self):
         swiftclient.Connection.put_container(
             mox.Regex(self.container_pattern),
@@ -123,7 +119,7 @@ class s3Test(unittest.TestCase):
         resource.delete()
         self.m.VerifyAll()
 
-    @skip_if(skip_test, 'unable to import swiftclient')
+    @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_public_read(self):
         swiftclient.Connection.put_container(
             mox.Regex(self.container_pattern),
@@ -141,7 +137,7 @@ class s3Test(unittest.TestCase):
         resource.delete()
         self.m.VerifyAll()
 
-    @skip_if(skip_test, 'unable to import swiftclient')
+    @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_public_read_write(self):
         swiftclient.Connection.put_container(
             mox.Regex(self.container_pattern),
@@ -159,7 +155,7 @@ class s3Test(unittest.TestCase):
         resource.delete()
         self.m.VerifyAll()
 
-    @skip_if(skip_test, 'unable to import swiftclient')
+    @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_authenticated_read(self):
         swiftclient.Connection.put_container(
             mox.Regex(self.container_pattern),
@@ -177,7 +173,7 @@ class s3Test(unittest.TestCase):
         resource.delete()
         self.m.VerifyAll()
 
-    @skip_if(skip_test, 'unable to import swiftclient')
+    @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_website(self):
 
         swiftclient.Connection.put_container(
@@ -196,7 +192,7 @@ class s3Test(unittest.TestCase):
         resource.delete()
         self.m.VerifyAll()
 
-    @skip_if(skip_test, 'unable to import swiftclient')
+    @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_delete_exception(self):
 
         swiftclient.Connection.put_container(
@@ -215,7 +211,7 @@ class s3Test(unittest.TestCase):
 
         self.m.VerifyAll()
 
-    @skip_if(skip_test, 'unable to import swiftclient')
+    @skip_if(swiftclient is None, 'unable to import swiftclient')
     def test_delete_retain(self):
 
         # first run, with retain policy