Merge "add more test cases to improve the test code coverage #4"

This commit is contained in:
Jenkins 2013-10-07 09:24:33 +00:00 committed by Gerrit Code Review
commit ebacf271ae
2 changed files with 51 additions and 1 deletions

View File

@ -80,4 +80,8 @@ class Evaluator(object):
@abc.abstractmethod
def evaluate(self, alarm):
pass
'''interface definition
evaluate an alarm
alarm Alarm: an instance of the Alarm
'''

View File

@ -0,0 +1,46 @@
# -*- encoding: utf-8 -*-
#
# Copyright © 2013 IBM Corp
#
# Author: Tong Li <litong01@us.ibm.com>
#
# 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.
"""class for tests in ceilometer/alarm/evaluator/__init__.py
"""
import mock
from ceilometer.tests import base
from ceilometer.alarm import evaluator
class TestEvaluatorBaseClass(base.TestCase):
def setUp(self):
super(TestEvaluatorBaseClass, self).setUp()
self.called = False
def _notify(self, alarm, previous, reason):
self.called = True
raise Exception('Boom!')
def test_base_refresh(self):
notifier = mock.MagicMock()
notifier.notify = self._notify
class EvaluatorSub(evaluator.Evaluator):
def evaluate(self, alarm):
pass
ev = EvaluatorSub(notifier)
ev.api_client = mock.MagicMock()
ev._refresh(mock.MagicMock(), mock.MagicMock(), mock.MagicMock())
self.assertTrue(self.called)