From 4888ab12fcd7eb1f660a4585da3ba8be82ae67a3 Mon Sep 17 00:00:00 2001 From: Zane Bitter Date: Mon, 11 Mar 2013 16:54:21 +0100 Subject: [PATCH] Avoid manipulating DB directly in unit test 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 | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/heat/tests/test_watch.py b/heat/tests/test_watch.py index 71fc8255..b2d0b4c9 100644 --- a/heat/tests/test_watch.py +++ b/heat/tests/test_watch.py @@ -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' -- 2.45.2