1
|
|
|
# Licensed to the StackStorm, Inc ('StackStorm') under one or more |
2
|
|
|
# contributor license agreements. See the NOTICE file distributed with |
3
|
|
|
# this work for additional information regarding copyright ownership. |
4
|
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0 |
5
|
|
|
# (the "License"); you may not use this file except in compliance with |
6
|
|
|
# the License. You may obtain 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, |
12
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13
|
|
|
# See the License for the specific language governing permissions and |
14
|
|
|
|
15
|
|
|
from opsgenie_base_test_case import OpsGenieBaseActionTestCase |
16
|
|
|
|
17
|
|
|
from enable_heartbeat import EnableHeartbeatAction |
18
|
|
|
|
19
|
|
|
|
20
|
|
|
class EnableHeartbeatTestCase(OpsGenieBaseActionTestCase): |
21
|
|
|
__test__ = True |
22
|
|
|
action_cls = EnableHeartbeatAction |
23
|
|
|
|
24
|
|
|
def test_run_api_404(self): |
25
|
|
|
action, adapter = self._get_action_status_code( |
26
|
|
|
'POST', |
27
|
|
|
"mock://api.opsgenie.com/v1/json/heartbeat/enable", |
28
|
|
|
status_code=404) |
29
|
|
|
|
30
|
|
|
self.assertRaises(ValueError, |
31
|
|
|
action.run, |
32
|
|
|
"Test") |
33
|
|
|
|
34
|
|
|
def test_run_invalid_json(self): |
35
|
|
|
action, adapter = self._get_action_invalid_json( |
36
|
|
|
'POST', |
37
|
|
|
"mock://api.opsgenie.com/v1/json/heartbeat/enable") |
38
|
|
|
|
39
|
|
|
self.assertRaises(ValueError, |
40
|
|
|
action.run, |
41
|
|
|
"Test") |
42
|
|
|
|
43
|
|
|
def test_run_api_success(self): |
44
|
|
|
expected = self.load_json("enable_heartbeat.json") |
45
|
|
|
|
46
|
|
|
action, adapter = self._get_mocked_action() |
47
|
|
|
adapter.register_uri('POST', |
48
|
|
|
"mock://api.opsgenie.com/v1/json/heartbeat/enable", |
49
|
|
|
text=self.get_fixture_content("enable_heartbeat.json")) |
50
|
|
|
|
51
|
|
|
result = action.run("Test") |
52
|
|
|
self.assertEqual(result, expected) |
53
|
|
|
|