Completed
Pull Request — master (#504)
by
unknown
03:36 queued 26s
created

ListHeartbeatsTestCase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A test_run_api_success() 0 10 1
A test_run_invalid_json() 0 7 1
A test_run_api_404() 0 8 1
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 list_heartbeats import ListHeartbeatsAction
18
19
20
class ListHeartbeatsTestCase(OpsGenieBaseActionTestCase):
21
    __test__ = True
22
    action_cls = ListHeartbeatsAction
23
24
    def test_run_api_404(self):
25
        action, adapter = self._get_action_status_code(
26
            'GET',
27
            "mock://api.opsgenie.com/v1/json/heartbeat",
28
            status_code=404)
29
30
        self.assertRaises(ValueError,
31
                          action.run)
32
33
    def test_run_invalid_json(self):
34
        action, adapter = self._get_action_invalid_json(
35
            'GET',
36
            "mock://api.opsgenie.com/v1/json/heartbeat")
37
38
        self.assertRaises(ValueError,
39
                          action.run)
40
41
    def test_run_api_success(self):
42
        expected = self.load_json("list_heartbeat.json")
43
44
        action, adapter = self._get_mocked_action()
45
        adapter.register_uri('GET',
46
                             "mock://api.opsgenie.com/v1/json/heartbeat",
47
                             text=self.get_fixture_content("list_heartbeat.json"))
48
49
        result = action.run()
50
        self.assertEqual(result, expected)
51