]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Adding resource initialization test
authorChris Alfonso <calfonso@redhat.com>
Tue, 17 Apr 2012 19:55:36 +0000 (15:55 -0400)
committerChris Alfonso <calfonso@redhat.com>
Mon, 23 Apr 2012 12:17:10 +0000 (08:17 -0400)
heat/tests/examples/test3.py
heat/tests/test_resources.py [new file with mode: 0644]
run_tests.py

index 714e18cd8d183bfbdfbf2e5e585bce44c874a212..22d1286249cfbd519e4eaf7918f6344571aa6a88 100644 (file)
@@ -11,7 +11,7 @@ from nose.plugins.attrib import attr
 # sets attribute on all test methods
 
 
-@attr(tag=['example', 'unittest'])
+@attr(tag=['example', 'unit'])
 @attr(speed='fast')
 class ExampleTest(unittest.TestCase):
     def test_a(self):
diff --git a/heat/tests/test_resources.py b/heat/tests/test_resources.py
new file mode 100644 (file)
index 0000000..2688eb2
--- /dev/null
@@ -0,0 +1,55 @@
+import sys
+
+import os
+import nose
+import unittest
+import mox
+from nose.plugins.attrib import attr
+from nose import with_setup
+from tests.v1_1 import fakes
+from heat.engine import resources
+from heat.common import config
+import heat.db as db_api
+
+@attr(tag=['unit', 'resource'])
+@attr(speed='fast')
+class ResourcesTest(unittest.TestCase):
+    _mox = None
+
+    def setUp(self):
+        cs = fakes.FakeClient()
+        self._mox = mox.Mox()
+        sql_connection = 'sqlite://heat.db'
+        conf = config.HeatEngineConfigOpts()
+        db_api.configure(conf)
+
+    def tearDown(self):
+        print "ResourcesTest teardown complete"
+
+    def test_initialize_resource_from_template(self):
+        f = open('templates/WordPress_Single_Instance_gold.template')
+        t = f.read()
+        f.close()
+
+        stack = self._mox.CreateMockAnything()
+        stack.id().AndReturn(1)
+        
+        self._mox.StubOutWithMock(stack, 'resolve_static_refs')
+        stack.resolve_static_refs(t).AndReturn(t)
+        
+        self._mox.StubOutWithMock(stack, 'resolve_find_in_map')
+        stack.resolve_find_in_map(t).AndReturn(t)
+
+        self._mox.StubOutWithMock(db_api, 'resource_get_by_name_and_stack')
+        db_api.resource_get_by_name_and_stack(None, 'test_resource_name', stack).AndReturn(None)
+
+        self._mox.ReplayAll()
+        resource = resources.Resource('test_resource_name', t, stack)
+
+        assert isinstance(resource, resources.Resource)
+
+    # allows testing of the test directly, shown below
+    if __name__ == '__main__':
+        sys.argv.append(__file__)
+        nose.main()
+   
index 73b185252d631f08cc50708f740e97ab423678e9..65fc5008204a2ea190bac24ef507e4f364c6b8ae 100644 (file)
@@ -42,6 +42,7 @@ import os
 import unittest
 import sys
 
+sys.path.append(os.environ['PYTHON_NOVACLIENT_SRC'])
 gettext.install('heat', unicode=1)
 
 from nose import config