Debian Codegraph @

aodhclient/tests/unit/test_alarm_history.py

raw
1 #
2 # Copyright IBM 2016. All rights reserved
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License"); you may
5 # not use this file except in compliance with the License. You may obtain
6 # a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 # License for the specific language governing permissions and limitations
14 # under the License.
15
16
17 from unittest import mock
18
19 import testtools
20
21 from aodhclient.v2 import alarm_history
22
23
24 class AlarmHistoryManagerTest(testtools.TestCase):
25
26 def setUp(self):
27 super().setUp()
28 self.client = mock.Mock()
29
30 @mock.patch.object(alarm_history.AlarmHistoryManager, '_get')
31 def test_get(self, mock_ahm):
32 ahm = alarm_history.AlarmHistoryManager(self.client)
33 ahm.get('01919bbd-8b0e-451c-be28-abe250ae9b1b')
34 mock_ahm.assert_called_with(
35 'v2/alarms/01919bbd-8b0e-451c-be28-abe250ae9b1b/history')
36
37 @mock.patch.object(alarm_history.AlarmHistoryManager, '_post')
38 def test_search(self, mock_ahm):
39 ahm = alarm_history.AlarmHistoryManager(self.client)
40 q = ('{"and": [{"=": {"type": "gnocchi_resources_threshold"}}, '
41 '{"=": {"alarm_id": "87bacbcb-a09c-4cb9-86d0-ad410dd8ad98"}}]}')
42 ahm.search(q)
43 expected_called_data = (
44 '{"filter": "{\\"and\\": ['
45 '{\\"=\\": {\\"type\\": \\"gnocchi_resources_threshold\\"}}, '
46 '{\\"=\\": {\\"alarm_id\\": '
47 '\\"87bacbcb-a09c-4cb9-86d0-ad410dd8ad98\\"}}]}"}')
48 mock_ahm.assert_called_with(
49 'v2/query/alarms/history',
50 data=expected_called_data,
51 headers={'Content-Type': 'application/json'})