def test_watch_rule_create_get(self): watch_rule = create_watch_rule(self.ctx, self.stack) ret_wr = db_api.watch_rule_get(self.ctx, watch_rule.id) self.assertIsNotNone(ret_wr) self.assertEqual('test_rule', ret_wr.name) self.assertEqual('{"foo": "123"}', dumps(ret_wr.rule)) self.assertEqual('normal', ret_wr.state) self.assertEqual(self.stack.id, ret_wr.stack_id)
def test_watch_rule_delete(self): watch_rule = create_watch_rule(self.ctx, self.stack) create_watch_data(self.ctx, watch_rule) db_api.watch_rule_delete(self.ctx, watch_rule.id) self.assertIsNone(db_api.watch_rule_get(self.ctx, watch_rule.id)) self.assertRaises(exception.NotFound, db_api.watch_rule_delete, self.ctx, UUID2) #Testing associated watch data deletion self.assertEqual([], db_api.watch_data_get_all(self.ctx))
def test_watch_rule_update(self): watch_rule = create_watch_rule(self.ctx, self.stack) values = { 'name': 'test_rule_1', 'rule': loads('{"foo": "bar"}'), 'state': 'nodata', } db_api.watch_rule_update(self.ctx, watch_rule.id, values) watch_rule = db_api.watch_rule_get(self.ctx, watch_rule.id) self.assertEqual('test_rule_1', watch_rule.name) self.assertEqual('{"foo": "bar"}', dumps(watch_rule.rule)) self.assertEqual('nodata', watch_rule.state) self.assertRaises(exception.NotFound, db_api.watch_rule_update, self.ctx, UUID2, values)
def get_by_id(cls, context, rule_id): db_rule = db_api.watch_rule_get(context, rule_id) return cls._from_db_object(context, cls(), db_rule)