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)
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),
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),
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),
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),
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(
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(
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