|
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
|
|
|
import yaml |
|
16
|
|
|
import json |
|
17
|
|
|
|
|
18
|
|
|
import requests_mock |
|
19
|
|
|
|
|
20
|
|
|
from st2tests.base import BaseActionTestCase |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
class OpsGenieBaseActionTestCase(BaseActionTestCase): |
|
24
|
|
|
__test__ = False |
|
25
|
|
|
|
|
26
|
|
|
def setUp(self): |
|
27
|
|
|
super(OpsGenieBaseActionTestCase, self).setUp() |
|
28
|
|
|
|
|
29
|
|
|
self._blank_config = self.load_yaml('blank.yaml') |
|
30
|
|
|
self._full_config = self.load_yaml('full.yaml') |
|
31
|
|
|
|
|
32
|
|
|
def load_yaml(self, filename): |
|
33
|
|
|
return yaml.safe_load(self.get_fixture_content(filename)) |
|
34
|
|
|
|
|
35
|
|
|
def load_json(self, filename): |
|
36
|
|
|
return json.loads(self.get_fixture_content(filename)) |
|
37
|
|
|
|
|
38
|
|
|
@property |
|
39
|
|
|
def blank_config(self): |
|
40
|
|
|
return self._blank_config |
|
41
|
|
|
|
|
42
|
|
|
@property |
|
43
|
|
|
def full_config(self): |
|
44
|
|
|
return self._full_config |
|
45
|
|
|
|
|
46
|
|
|
def test_run_no_config(self): |
|
47
|
|
|
self.assertRaises(ValueError, |
|
48
|
|
|
self.action_cls, |
|
49
|
|
|
self.blank_config) |
|
50
|
|
|
|
|
51
|
|
|
def test_run_is_instance(self): |
|
52
|
|
|
action = self.get_action_instance(self.full_config) |
|
53
|
|
|
self.assertIsInstance(action, self.action_cls) |
|
54
|
|
|
self.assertEqual(action.api_key, "ApiKey") |
|
55
|
|
|
self.assertEqual(action.api_host, "mock://api.opsgenie.com/") |
|
56
|
|
|
|
|
57
|
|
|
def _get_mocked_action(self): |
|
58
|
|
|
action = self.get_action_instance(self.full_config) |
|
59
|
|
|
adapter = requests_mock.Adapter() |
|
60
|
|
|
action.session.mount('mock', adapter) |
|
61
|
|
|
|
|
62
|
|
|
return action, adapter |
|
63
|
|
|
|
|
64
|
|
|
def _get_action_invalid_json(self, method, url): |
|
65
|
|
|
action, adapter = self._get_mocked_action() |
|
66
|
|
|
adapter.register_uri(method, |
|
67
|
|
|
url, |
|
68
|
|
|
text="{'ffo': bar}") |
|
69
|
|
|
return action, adapter |
|
70
|
|
|
|
|
71
|
|
|
def _get_action_status_code(self, method, url, status_code): |
|
72
|
|
|
action, adapter = self._get_mocked_action() |
|
73
|
|
|
adapter.register_uri(method, |
|
74
|
|
|
url, |
|
75
|
|
|
status_code=status_code) |
|
76
|
|
|
return action, adapter |
|
77
|
|
|
|