]> review.fuel-infra Code Review - openstack-build/heat-build.git/commitdiff
Avoid manipulating DB directly in unit test
authorZane Bitter <zbitter@redhat.com>
Mon, 11 Mar 2013 15:54:21 +0000 (16:54 +0100)
committerZane Bitter <zbitter@redhat.com>
Mon, 11 Mar 2013 16:36:06 +0000 (17:36 +0100)
Use the parser.Stack class for inserting data into the database in the
watch rule unit tests. If there is direct database manipulation in the unit
tests, it risks falling out of step with the implementation in the code (in
this case, by not supplying the disable_rollback value).

(Required to squash DB migrations, bug 1072949)

Change-Id: I66e5a0093d20222c876f52e626043704777dcb6a

heat/tests/test_watch.py

index 71fc82555638aea0e9659a7ec968f46688345a65..b2d0b4c9ee8ddf798db172b851703b0cb95f0ce7 100644 (file)
@@ -45,21 +45,17 @@ class WatchRuleTest(unittest.TestCase):
         # Create a dummy stack in the DB as WatchRule instances
         # must be associated with a stack
         ctx = context.get_admin_context()
+        ctx.username = 'dummyuser'
+        ctx.tenant_id = '123456'
         empty_tmpl = {"template": {}}
-        tmpl = db_api.raw_template_create(ctx, empty_tmpl)
-        dummy_stack = {'id': '6754d843-bed2-40dc-a325-84882bb90a98',
-                       'name': 'dummystack',
-                       'raw_template_id': tmpl.id,
-                       'user_creds_id': 1,
-                       'username': 'dummyuser',
-                       'owner_id': None,
-                       'status': 'CREATE_COMPLETE',
-                       'status_reason': 'foo status',
-                       'parameters': {'foo': 'bar'},
-                       'timeout': 60,
-                       'tenant': 123456}
-        db_ret = db_api.stack_create(ctx, dummy_stack)
-        cls.stack_id = db_ret.id
+        tmpl = parser.Template(empty_tmpl)
+        stack_name = 'dummystack'
+        params = parser.Parameters(stack_name, tmpl, {'foo': 'bar'})
+        dummy_stack = parser.Stack(ctx, stack_name, tmpl, params)
+        dummy_stack.state_set(dummy_stack.CREATE_COMPLETE, 'Testing')
+        dummy_stack.store()
+
+        cls.stack_id = dummy_stack.id
 
     def setUp(self):
         self.username = 'watchrule_test_user'