]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Removing all prints and capturing logging
authorClint Byrum <clint@fewbar.com>
Thu, 25 Apr 2013 23:33:48 +0000 (16:33 -0700)
committerClint Byrum <clint@fewbar.com>
Tue, 30 Apr 2013 20:51:31 +0000 (13:51 -0700)
A new base class for tests is used to reduce repetitive steps used in
a majority of tests. This new base class also uses fixtures.FakeLogger
to suppress logging, though it will be shown on any failures to aid in
debugging the failure.

Prints that happen on normal operation of the test suite are all removed
as they are not needed and only clutter the output.

Change-Id: I0365283ce415c5390fd68bdf1f0b3c8038b1b9af

heat/tests/common.py [new file with mode: 0644]
heat/tests/test_api_aws.py
heat/tests/test_api_cfn_v1.py
heat/tests/test_api_cloudwatch.py
heat/tests/test_common_policy.py
heat/tests/test_dbinstance.py
heat/tests/test_loadbalancer.py
heat/tests/test_nested_stack.py
heat/tests/test_volume.py
heat/tests/utils.py

diff --git a/heat/tests/common.py b/heat/tests/common.py
new file mode 100644 (file)
index 0000000..1d7970a
--- /dev/null
@@ -0,0 +1,27 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+#    Licensed under the Apache License, Version 2.0 (the "License"); you may
+#    not use this file except in compliance with the License. You may obtain
+#    a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#    Unless required by applicable law or agreed to in writing, software
+#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+#    License for the specific language governing permissions and limitations
+#    under the License.
+
+
+import fixtures
+import mox
+import testtools
+
+
+class HeatTestCase(testtools.TestCase):
+
+    def setUp(self):
+        super(HeatTestCase, self).setUp()
+        self.m = mox.Mox()
+        self.addCleanup(self.m.UnsetStubs)
+        self.useFixture(fixtures.FakeLogger())
index 507b4dcb3657c96e180806d18c07e3a6ea2941d4..a54a5eb677b77bb84a2710a01345a129e02de337 100644 (file)
@@ -13,7 +13,7 @@
 #    under the License.
 
 
-import unittest
+from heat.tests.common import HeatTestCase
 from nose.plugins.attrib import attr
 
 from heat.api.aws import utils as api_utils
@@ -21,7 +21,7 @@ from heat.api.aws import utils as api_utils
 
 @attr(tag=['unit', 'api-aws', 'AWSCommon'])
 @attr(speed='fast')
-class AWSCommon(unittest.TestCase):
+class AWSCommon(HeatTestCase):
     '''
     Tests the api/aws common componenents
     '''
@@ -187,9 +187,3 @@ class AWSCommon(unittest.TestCase):
         expected = {"bar": 123}
         result = api_utils.reformat_dict_keys(keymap, data)
         self.assertEqual(result, expected)
-
-    def setUp(self):
-        print "setup complete"
-
-    def tearDown(self):
-        print "teardown complete"
index 151893e9d471460c45e31ab0d7eb12149ac9e107..a13363f9595f1ed13a8d13ea282c1db983bf0802 100644 (file)
@@ -14,9 +14,7 @@
 
 import json
 import os
-import unittest
 
-import mox
 from nose.plugins.attrib import attr
 from oslo.config import cfg
 
@@ -29,11 +27,14 @@ from heat.common.wsgi import Request
 from heat.rpc import api as rpc_api
 from heat.api.aws import exception
 import heat.api.cfn.v1.stacks as stacks
+from heat.tests.common import HeatTestCase
+
+policy_path = os.path.dirname(os.path.realpath(__file__)) + "/policy/"
 
 
 @attr(tag=['unit', 'api-cfn-v1-stacks', 'StackController'])
 @attr(speed='fast')
-class CfnStackControllerTest(unittest.TestCase):
+class CfnStackControllerTest(HeatTestCase):
     '''
     Tests the API class which acts as the WSGI controller,
     the endpoint processing API requests after they are routed
@@ -87,7 +88,7 @@ class CfnStackControllerTest(unittest.TestCase):
         params = {'Action': 'ListStacks'}
         dummy_req = self._dummy_GET_request(params)
         dummy_req.context.roles = ['heat_stack_user']
-        self.controller.policy.policy_path = (self.policy_path +
+        self.controller.policy.policy_path = (policy_path +
                                               'deny_stack_user.json')
         self.assertRaises(exception.HeatAccessDeniedError,
                           self.controller._enforce, dummy_req, 'ListStacks')
@@ -103,7 +104,7 @@ class CfnStackControllerTest(unittest.TestCase):
                                 ).AndRaise(AttributeError)
         self.m.ReplayAll()
 
-        self.controller.policy.policy_path = (self.policy_path +
+        self.controller.policy.policy_path = (policy_path +
                                               'deny_stack_user.json')
         self.assertRaises(exception.HeatInternalFailureError,
                           self.controller._enforce, dummy_req, 'ListStacks')
@@ -1396,13 +1397,10 @@ class CfnStackControllerTest(unittest.TestCase):
         self.m.VerifyAll()
 
     def setUp(self):
-        self.maxDiff = None
-        self.m = mox.Mox()
+        super(CfnStackControllerTest, self).setUp()
 
-        self.path = os.path.dirname(os.path.realpath(__file__))
-        self.policy_path = self.path + "/policy/"
         opts = [
-            cfg.StrOpt('config_dir', default=self.policy_path),
+            cfg.StrOpt('config_dir', default=policy_path),
             cfg.StrOpt('config_file', default='foo'),
             cfg.StrOpt('project', default='heat'),
         ]
@@ -1416,8 +1414,3 @@ class CfnStackControllerTest(unittest.TestCase):
             bind_port = 8000
         cfgopts = DummyConfig()
         self.controller = stacks.StackController(options=cfgopts)
-        print "setup complete"
-
-    def tearDown(self):
-        self.m.UnsetStubs()
-        print "teardown complete"
index a237f7a374d8fa5c59f4c326680174986df0c0eb..ed189c68a8f74c7fe2866b84013cafae49c2bdf8 100644 (file)
@@ -13,9 +13,7 @@
 #    under the License.
 
 import os
-import unittest
 
-import mox
 from nose.plugins.attrib import attr
 from oslo.config import cfg
 
@@ -25,13 +23,13 @@ from heat.openstack.common import rpc
 from heat.common.wsgi import Request
 from heat.api.aws import exception
 import heat.api.cloudwatch.watch as watches
-from heat.engine import api as engine_api
-from heat.rpc import api as rpc_api
+from heat.rpc import api as engine_api
+from heat.tests.common import HeatTestCase
 
 
 @attr(tag=['unit', 'api-cloudwatch', 'WatchController'])
 @attr(speed='fast')
-class WatchControllerTest(unittest.TestCase):
+class WatchControllerTest(HeatTestCase):
     '''
     Tests the API class which acts as the WSGI controller,
     the endpoint processing API requests after they are routed
@@ -510,9 +508,7 @@ class WatchControllerTest(unittest.TestCase):
         self.assert_(type(result) == exception.HeatInvalidParameterValueError)
 
     def setUp(self):
-        self.maxDiff = None
-        self.m = mox.Mox()
-
+        super(WatchControllerTest, self).setUp()
         self.path = os.path.dirname(os.path.realpath(__file__))
         self.policy_path = self.path + "/policy/"
         opts = [
@@ -522,7 +518,7 @@ class WatchControllerTest(unittest.TestCase):
         ]
         cfg.CONF.register_opts(opts)
         cfg.CONF.set_default('host', 'host')
-        self.topic = rpc_api.ENGINE_TOPIC
+        self.topic = engine_api.ENGINE_TOPIC
         self.api_version = '1.0'
 
         # Create WSGI controller instance
@@ -531,9 +527,7 @@ class WatchControllerTest(unittest.TestCase):
         cfgopts = DummyConfig()
         self.controller = watches.WatchController(options=cfgopts)
         self.controller.policy.policy_path = None
-        print "setup complete"
 
     def tearDown(self):
-        self.m.UnsetStubs()
         self.m.VerifyAll()
-        print "teardown complete"
+        super(WatchControllerTest, self).tearDown()
index 7915b3c51ce1824dea82cba515122857c82ce56e..af8bb0534d63ac1bc69f66b64ff141bd007e118b 100644 (file)
@@ -24,6 +24,8 @@ from heat.common import context
 from heat.common import policy
 from heat.common import exception
 
+policy_path = os.path.dirname(os.path.realpath(__file__)) + "/policy/"
+
 
 @attr(tag=['unit', 'common-policy', 'Enforcer'])
 @attr(speed='fast')
@@ -40,19 +42,16 @@ class TestPolicyEnforcer(unittest.TestCase):
                   "PutMetricAlarm", "PutMetricData", "SetAlarmState")
 
     def setUp(self):
-        self.path = os.path.dirname(os.path.realpath(__file__)) + "/policy/"
         self.m = mox.Mox()
         opts = [
-            cfg.StrOpt('config_dir', default=self.path),
+            cfg.StrOpt('config_dir', default=policy_path),
             cfg.StrOpt('config_file', default='foo'),
             cfg.StrOpt('project', default='heat'),
         ]
         cfg.CONF.register_opts(opts)
-        print "setup complete"
 
     def tearDown(self):
         self.m.UnsetStubs()
-        print "teardown complete"
 
     def test_policy_cfn_default(self):
         enforcer = policy.Enforcer(scope='cloudformation')
@@ -63,7 +62,7 @@ class TestPolicyEnforcer(unittest.TestCase):
             enforcer.enforce(ctx, action, {})
 
     def test_policy_cfn_notallowed(self):
-        pf = self.path + 'notallowed.json'
+        pf = policy_path + 'notallowed.json'
         self.m.StubOutWithMock(policy.Enforcer, '_find_policy_file')
         policy.Enforcer._find_policy_file().MultipleTimes().AndReturn(pf)
         self.m.ReplayAll()
@@ -78,7 +77,7 @@ class TestPolicyEnforcer(unittest.TestCase):
         self.m.VerifyAll()
 
     def test_policy_cfn_deny_stack_user(self):
-        pf = self.path + 'deny_stack_user.json'
+        pf = policy_path + 'deny_stack_user.json'
         self.m.StubOutWithMock(policy.Enforcer, '_find_policy_file')
         policy.Enforcer._find_policy_file().MultipleTimes().AndReturn(pf)
         self.m.ReplayAll()
@@ -96,7 +95,7 @@ class TestPolicyEnforcer(unittest.TestCase):
         self.m.VerifyAll()
 
     def test_policy_cfn_allow_non_stack_user(self):
-        pf = self.path + 'deny_stack_user.json'
+        pf = policy_path + 'deny_stack_user.json'
         self.m.StubOutWithMock(policy.Enforcer, '_find_policy_file')
         policy.Enforcer._find_policy_file().MultipleTimes().AndReturn(pf)
         self.m.ReplayAll()
@@ -110,7 +109,7 @@ class TestPolicyEnforcer(unittest.TestCase):
         self.m.VerifyAll()
 
     def test_policy_cw_deny_stack_user(self):
-        pf = self.path + 'deny_stack_user.json'
+        pf = policy_path + 'deny_stack_user.json'
         self.m.StubOutWithMock(policy.Enforcer, '_find_policy_file')
         policy.Enforcer._find_policy_file().MultipleTimes().AndReturn(pf)
         self.m.ReplayAll()
@@ -128,7 +127,7 @@ class TestPolicyEnforcer(unittest.TestCase):
         self.m.VerifyAll()
 
     def test_policy_cw_allow_non_stack_user(self):
-        pf = self.path + 'deny_stack_user.json'
+        pf = policy_path + 'deny_stack_user.json'
         self.m.StubOutWithMock(policy.Enforcer, '_find_policy_file')
         policy.Enforcer._find_policy_file().MultipleTimes().AndReturn(pf)
         self.m.ReplayAll()
index e4d018f9b7d010dcd8ab1f4141b530f6bdef4c1b..dfea6007560897f050374475ed791aa821a4117f 100644 (file)
@@ -15,7 +15,6 @@
 
 import os
 
-import unittest
 import mox
 
 from nose.plugins.attrib import attr
@@ -26,20 +25,17 @@ from heat.common import template_format
 from heat.engine import parser
 from heat.engine import scheduler
 from heat.engine.resources import dbinstance as dbi
+from heat.tests.common import HeatTestCase
 
 
 @attr(tag=['unit', 'resource'])
 @attr(speed='fast')
-class DBInstanceTest(unittest.TestCase):
+class DBInstanceTest(HeatTestCase):
     def setUp(self):
-        self.m = mox.Mox()
+        super(DBInstanceTest, self).setUp()
         self.m.StubOutWithMock(dbi.DBInstance, 'create_with_template')
         self.m.StubOutWithMock(dbi.DBInstance, 'nested')
 
-    def tearDown(self):
-        self.m.UnsetStubs()
-        print "DBInstanceTest teardown complete"
-
     def load_template(self):
         self.path = os.path.dirname(os.path.realpath(__file__)).\
             replace('heat/tests', 'templates')
index 518af1f3c307f6db39e04c71538adf6b6f58925f..7ac28b52a3229c23b3a3e3cd0199459f88d1028a 100644 (file)
 #    under the License.
 
 
+import mox
 import re
 import os
 
-import unittest
-import mox
-
 from nose.plugins.attrib import attr
 
 from oslo.config import cfg
@@ -33,6 +31,7 @@ from heat.engine.resources import user
 from heat.engine.resources import loadbalancer as lb
 from heat.engine.resources import wait_condition as wc
 from heat.engine.resource import Metadata
+from heat.tests.common import HeatTestCase
 from heat.tests.utils import setup_dummy_db
 from heat.tests.v1_1 import fakes
 from heat.tests import fakes as test_fakes
@@ -50,10 +49,10 @@ def create_context(mocks, user='lb_test_user',
 
 @attr(tag=['unit', 'resource'])
 @attr(speed='fast')
-class LoadBalancerTest(unittest.TestCase):
+class LoadBalancerTest(HeatTestCase):
     def setUp(self):
+        super(LoadBalancerTest, self).setUp()
         config.register_engine_opts()
-        self.m = mox.Mox()
         self.fc = fakes.FakeClient()
         self.m.StubOutWithMock(lb.LoadBalancer, 'nova')
         self.m.StubOutWithMock(instance.Instance, 'nova')
@@ -66,10 +65,6 @@ class LoadBalancerTest(unittest.TestCase):
                              'http://127.0.0.1:8000/v1/waitcondition')
         setup_dummy_db()
 
-    def tearDown(self):
-        self.m.UnsetStubs()
-        print "LoadBalancerTest teardown complete"
-
     def load_template(self):
         self.path = os.path.dirname(os.path.realpath(__file__)).\
             replace('heat/tests', 'templates')
index f2bb96b20e87885c6fa49ba3fef46d339310d98e..4c1db81343138050cb300f817a46ff3ce3f8ca79 100644 (file)
@@ -13,9 +13,6 @@
 #    under the License.
 
 
-import unittest
-import mox
-
 from nose.plugins.attrib import attr
 
 from heat.common import context
@@ -24,12 +21,13 @@ from heat.common import template_format
 from heat.engine import parser
 from heat.engine.resources import stack as nested_stack
 from heat.common import urlfetch
+from heat.tests.common import HeatTestCase
 from heat.tests.utils import setup_dummy_db
 
 
 @attr(tag=['unit', 'resource'])
 @attr(speed='fast')
-class NestedStackTest(unittest.TestCase):
+class NestedStackTest(HeatTestCase):
     test_template = '''
 HeatTemplateFormatVersion: '2012-12-12'
 Resources:
@@ -49,14 +47,10 @@ Outputs:
 '''
 
     def setUp(self):
-        self.m = mox.Mox()
+        super(NestedStackTest, self).setUp()
         self.m.StubOutWithMock(urlfetch, 'get')
         setup_dummy_db()
 
-    def tearDown(self):
-        self.m.UnsetStubs()
-        print "NestedStackTest teardown complete"
-
     def create_stack(self, template):
         t = template_format.parse(template)
         stack = self.parse_stack(t)
index 5cc39bb55a1ed652a3384cc087e6b88430938f17..7fb133f8a105cd4ce3dc52741ffae6f0e30676cb 100644 (file)
@@ -16,8 +16,6 @@
 import os
 
 import eventlet
-import mox
-import unittest
 
 from nose.plugins.attrib import attr
 
@@ -28,15 +26,16 @@ from heat.engine import parser
 from heat.engine import scheduler
 from heat.engine.resources import volume as vol
 from heat.engine import clients
+from heat.tests.common import HeatTestCase
 from heat.tests.v1_1 import fakes
 from heat.tests.utils import setup_dummy_db
 
 
 @attr(tag=['unit', 'resource', 'volume'])
 @attr(speed='fast')
-class VolumeTest(unittest.TestCase):
+class VolumeTest(HeatTestCase):
     def setUp(self):
-        self.m = mox.Mox()
+        super(VolumeTest, self).setUp()
         self.fc = fakes.FakeClient()
         self.m.StubOutWithMock(clients.OpenStackClients, 'cinder')
         self.m.StubOutWithMock(clients.OpenStackClients, 'nova')
@@ -48,10 +47,6 @@ class VolumeTest(unittest.TestCase):
         self.m.StubOutWithMock(eventlet, 'sleep')
         setup_dummy_db()
 
-    def tearDown(self):
-        self.m.UnsetStubs()
-        print "VolumeTest teardown complete"
-
     def load_template(self):
         self.path = os.path.dirname(os.path.realpath(__file__)).\
             replace('heat/tests', 'templates')
index 93056a895a219c8f30059f86cb89e33ae07970d9..d9da8f3fa7c66e7f68467b637fbede9f020f2bc9 100644 (file)
@@ -72,15 +72,13 @@ def stack_delete_after(test_fn):
     to ensure tests clean up their stacks regardless of test success/failure
     """
     def wrapped_test(test_cls):
-        #print "Running test", test_fn.__name__
         try:
             test_fn(test_cls)
         finally:
             try:
                 test_cls.stack.delete()
             except AttributeError:
-                print "Could not delete stack (already deleted?)"
-        #print "Exited", test_fn.__name__
+                pass
     return wrapped_test