diff options
| author | Jenkins <jenkins@review.openstack.org> | 2013-10-03 00:34:08 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2013-10-03 00:34:08 +0000 |
| commit | 0a6a6b4d099f627e71ca22dd9d376da2f54d4f90 (patch) | |
| tree | 3f643fd562293fbbc844ddff6abaed0a8bdaf5a9 | |
| parent | 66ef360c1480899bcdf6ad7af8f2d581b532c5e6 (diff) | |
| parent | 7c8a676b43e9f82276041afbae15d739dc2c1ab4 (diff) | |
| download | python-ceilometerclient-0a6a6b4d099f627e71ca22dd9d376da2f54d4f90.tar.gz | |
Merge "Fix shell.do_alarm_get_state to get as opposed to set"
| -rw-r--r-- | ceilometerclient/tests/v2/test_shell.py | 39 | ||||
| -rw-r--r-- | ceilometerclient/v2/shell.py | 6 | ||||
| -rw-r--r-- | test-requirements.txt | 1 |
3 files changed, 42 insertions, 4 deletions
diff --git a/ceilometerclient/tests/v2/test_shell.py b/ceilometerclient/tests/v2/test_shell.py new file mode 100644 index 0000000..c758619 --- /dev/null +++ b/ceilometerclient/tests/v2/test_shell.py @@ -0,0 +1,39 @@ +# 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. + +import mock + +from ceilometerclient.tests import utils +from ceilometerclient.v2 import shell as ceilometer_shell + + +class ShellAlarmStateCommandsTest(utils.BaseTestCase): + + ALARM_ID = 'foobar' + + def setUp(self): + super(ShellAlarmStateCommandsTest, self).setUp() + self.cc = mock.Mock() + self.cc.alarms = mock.Mock() + self.args = mock.Mock() + self.args.alarm_id = self.ALARM_ID + + def test_alarm_state_get(self): + ceilometer_shell.do_alarm_get_state(self.cc, self.args) + self.cc.alarms.get_state.assert_called_once_with(self.ALARM_ID) + self.assertFalse(self.cc.alarms.set_state.called) + + def test_alarm_state_set(self): + self.args.state = 'ok' + ceilometer_shell.do_alarm_set_state(self.cc, self.args) + self.cc.alarms.set_state.assert_called_once_with(self.ALARM_ID, 'ok') + self.assertFalse(self.cc.alarms.get_state.called) diff --git a/ceilometerclient/v2/shell.py b/ceilometerclient/v2/shell.py index 60fa107..571aa33 100644 --- a/ceilometerclient/v2/shell.py +++ b/ceilometerclient/v2/shell.py @@ -427,10 +427,9 @@ def do_alarm_delete(cc, args={}): def do_alarm_set_state(cc, args={}): '''Set the state of an alarm.''' try: - cc.alarms.set_state(args.alarm_id, args.state) + state = cc.alarms.set_state(args.alarm_id, args.state) except exc.HTTPNotFound: raise exc.CommandError('Alarm not found: %s' % args.alarm_id) - state = cc.alarms.get_state(args.alarm_id) utils.print_dict({'state': state}, wrap=72) @@ -439,10 +438,9 @@ def do_alarm_set_state(cc, args={}): def do_alarm_get_state(cc, args={}): '''Get the state of an alarm.''' try: - cc.alarms.set_state(args.alarm_id, args.state) + state = cc.alarms.get_state(args.alarm_id) except exc.HTTPNotFound: raise exc.CommandError('Alarm not found: %s' % args.alarm_id) - state = cc.alarms.get_state(args.alarm_id) utils.print_dict({'state': state}, wrap=72) diff --git a/test-requirements.txt b/test-requirements.txt index a3e4bfc..26843ce 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -6,6 +6,7 @@ hacking>=0.5.6,<0.8 coverage>=3.6 discover fixtures>=0.3.14 +mock>=1.0 mox>=0.5.3 python-subunit sphinx>=1.1.2 |
