From: Angus Salkeld Date: Wed, 6 Feb 2013 11:25:22 +0000 (+1100) Subject: test_s3: use try_import from common X-Git-Tag: 2014.1~924^2 X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=215de3e28c4a378327e52dc5cafcb5de39653ad9;p=openstack-build%2Fheat-build.git test_s3: use try_import from common Change-Id: I3055c3d2f8061b91b038286d8ff2c5cbdcd41efd --- diff --git a/heat/tests/test_s3.py b/heat/tests/test_s3.py index 9d1db47d..709b5a51 100644 --- a/heat/tests/test_s3.py +++ b/heat/tests/test_s3.py @@ -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