Completed
Pull Request — master (#504)
by
unknown
03:04
created

DeleteAlertsActionTestCase   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

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

3 Methods

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