Completed
Push — master ( da306e...c5fe8d )
by Jaspar
17s queued 15s
created

tests.protocols.gmpv208.entities.alerts.test_trigger_alert   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 90
rs 10
c 0
b 0
f 0
wmc 12

8 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpTriggerAlertTestMixin.test_trigger_alert_without_alert_id() 0 6 3
A GmpTriggerAlertTestMixin.test_trigger_alert_with_filter() 0 5 1
A GmpTriggerAlertTestMixin.test_trigger_alert_with_report_format_type() 0 10 1
A GmpTriggerAlertTestMixin.test_trigger_alert_without_report_id() 0 6 3
A GmpTriggerAlertTestMixin.test_trigger_alert_with_delta_report_id() 0 7 1
A GmpTriggerAlertTestMixin.test_trigger_alert() 0 5 1
A GmpTriggerAlertTestMixin.test_trigger_alert_with_report_format_id() 0 7 1
A GmpTriggerAlertTestMixin.test_trigger_alert_with_filter_id() 0 5 1
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2018-2021 Greenbone Networks GmbH
3
#
4
# SPDX-License-Identifier: GPL-3.0-or-later
5
#
6
# This program is free software: you can redistribute it and/or modify
7
# it under the terms of the GNU General Public License as published by
8
# the Free Software Foundation, either version 3 of the License, or
9
# (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
from gvm.errors import RequiredArgument
20
from gvm.protocols.gmpv208.entities.report_formats import (
21
    ReportFormatType,
22
    get_report_format_id_from_string,
23
)
24
25
26
class GmpTriggerAlertTestMixin:
27
    def test_trigger_alert_without_alert_id(self):
28
        with self.assertRaises(RequiredArgument):
29
            self.gmp.trigger_alert(alert_id=None, report_id='r1')
30
31
        with self.assertRaises(RequiredArgument):
32
            self.gmp.trigger_alert(alert_id='', report_id='r1')
33
34
    def test_trigger_alert_without_report_id(self):
35
        with self.assertRaises(RequiredArgument):
36
            self.gmp.trigger_alert(alert_id='a1', report_id=None)
37
38
        with self.assertRaises(RequiredArgument):
39
            self.gmp.trigger_alert(alert_id='a1', report_id='')
40
41
    def test_trigger_alert(self):
42
        self.gmp.trigger_alert(alert_id='a1', report_id='r1')
43
44
        self.connection.send.has_been_called_with(
45
            '<get_reports report_id="r1" alert_id="a1"/>'
46
        )
47
48
    def test_trigger_alert_with_filter(self):
49
        self.gmp.trigger_alert(alert_id='a1', report_id='r1', filter='name=foo')
50
51
        self.connection.send.has_been_called_with(
52
            '<get_reports report_id="r1" alert_id="a1" filter="name=foo"/>'
53
        )
54
55
    def test_trigger_alert_with_filter_id(self):
56
        self.gmp.trigger_alert(alert_id="a1", report_id='r1', filter_id='f1')
57
58
        self.connection.send.has_been_called_with(
59
            '<get_reports report_id="r1" alert_id="a1" filt_id="f1"/>'
60
        )
61
62
    def test_trigger_alert_with_report_format_id(self):
63
        self.gmp.trigger_alert(
64
            alert_id="a1", report_id='r1', report_format_id='bar'
65
        )
66
67
        self.connection.send.has_been_called_with(
68
            '<get_reports report_id="r1" alert_id="a1" format_id="bar"/>'
69
        )
70
71
    def test_trigger_alert_with_report_format_type(self):
72
        self.gmp.trigger_alert(
73
            alert_id="a1", report_id='r1', report_format_id=ReportFormatType.SVG
74
        )
75
76
        report_format_id = get_report_format_id_from_string('svg').value
77
78
        self.connection.send.has_been_called_with(
79
            '<get_reports report_id="r1" alert_id="a1" '
80
            'format_id="{}"/>'.format(report_format_id)
81
        )
82
83
    def test_trigger_alert_with_delta_report_id(self):
84
        self.gmp.trigger_alert(
85
            alert_id='a1', report_id='r1', delta_report_id='r2'
86
        )
87
88
        self.connection.send.has_been_called_with(
89
            '<get_reports report_id="r1" alert_id="a1" delta_report_id="r2"/>'
90
        )
91