Completed
Push — master ( e81db1...a7ad2f )
by Björn
17s queued 13s
created

GmpModifyNoteTestCase.test_modify_note_missing_text()   A

Complexity

Conditions 4

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2020 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
import unittest
20
21
from decimal import Decimal
22
23
from gvm.errors import RequiredArgument
24
25
from gvm.protocols.gmpv214 import SeverityLevel
26
27
28
class GmpModifyNoteTestCase:
29
    def test_modify_note(self):
30
        self.gmp.modify_note(note_id='n1', text='foo')
31
32
        self.connection.send.has_been_called_with(
33
            '<modify_note note_id="n1">' '<text>foo</text>' '</modify_note>'
34
        )
35
36
    def test_modify_note_missing_note_id(self):
37
        with self.assertRaises(RequiredArgument):
38
            self.gmp.modify_note(note_id=None, text='foo')
39
40
        with self.assertRaises(RequiredArgument):
41
            self.gmp.modify_note(note_id='', text='foo')
42
43
        with self.assertRaises(RequiredArgument):
44
            self.gmp.modify_note('', text='foo')
45
46
    def test_modify_note_missing_text(self):
47
        with self.assertRaises(RequiredArgument):
48
            self.gmp.modify_note(note_id='n1', text='')
49
50
        with self.assertRaises(RequiredArgument):
51
            self.gmp.modify_note(note_id='n1', text=None)
52
53
        with self.assertRaises(RequiredArgument):
54
            self.gmp.modify_note('n1', '')
55
56
    def test_modify_note_with_days_active(self):
57
        self.gmp.modify_note(note_id='n1', text='foo', days_active=0)
58
59
        self.connection.send.has_been_called_with(
60
            '<modify_note note_id="n1">'
61
            '<text>foo</text>'
62
            '<active>0</active>'
63
            '</modify_note>'
64
        )
65
66
        self.gmp.modify_note(note_id='n1', text='foo', days_active=-1)
67
68
        self.connection.send.has_been_called_with(
69
            '<modify_note note_id="n1">'
70
            '<text>foo</text>'
71
            '<active>-1</active>'
72
            '</modify_note>'
73
        )
74
75
        self.gmp.modify_note(note_id='n1', text='foo', days_active=600)
76
77
        self.connection.send.has_been_called_with(
78
            '<modify_note note_id="n1">'
79
            '<text>foo</text>'
80
            '<active>600</active>'
81
            '</modify_note>'
82
        )
83
84
    def test_modify_note_with_port(self):
85
        self.gmp.modify_note(note_id='n1', text='foo', port='123')
86
87
        self.connection.send.has_been_called_with(
88
            '<modify_note note_id="n1">'
89
            '<text>foo</text>'
90
            '<port>123</port>'
91
            '</modify_note>'
92
        )
93
94
        self.gmp.modify_note(note_id='n1', text='foo', port=123)
95
96
        self.connection.send.has_been_called_with(
97
            '<modify_note note_id="n1">'
98
            '<text>foo</text>'
99
            '<port>123</port>'
100
            '</modify_note>'
101
        )
102
103
    def test_modify_note_with_hosts(self):
104
        self.gmp.modify_note(note_id='n1', text='foo', hosts=['foo'])
105
106
        self.connection.send.has_been_called_with(
107
            '<modify_note note_id="n1">'
108
            '<text>foo</text>'
109
            '<hosts>foo</hosts>'
110
            '</modify_note>'
111
        )
112
113
        self.gmp.modify_note(note_id='n1', text='foo', hosts=['foo', 'bar'])
114
115
        self.connection.send.has_been_called_with(
116
            '<modify_note note_id="n1">'
117
            '<text>foo</text>'
118
            '<hosts>foo,bar</hosts>'
119
            '</modify_note>'
120
        )
121
122
    def test_modify_note_with_result_id(self):
123
        self.gmp.modify_note(note_id='n1', text='foo', result_id='r1')
124
125
        self.connection.send.has_been_called_with(
126
            '<modify_note note_id="n1">'
127
            '<text>foo</text>'
128
            '<result id="r1"/>'
129
            '</modify_note>'
130
        )
131
132
    def test_modify_note_with_task_id(self):
133
        self.gmp.modify_note(note_id='n1', text='foo', task_id='r1')
134
135
        self.connection.send.has_been_called_with(
136
            '<modify_note note_id="n1">'
137
            '<text>foo</text>'
138
            '<task id="r1"/>'
139
            '</modify_note>'
140
        )
141
142
    def test_modify_note_with_severity(self):
143
        self.gmp.modify_note(note_id='n1', text='foo', severity='5.5')
144
145
        self.connection.send.has_been_called_with(
146
            '<modify_note note_id="n1">'
147
            '<text>foo</text>'
148
            '<severity>5.5</severity>'
149
            '</modify_note>'
150
        )
151
152
        self.gmp.modify_note(note_id='n1', text='foo', severity=5.5)
153
154
        self.connection.send.has_been_called_with(
155
            '<modify_note note_id="n1">'
156
            '<text>foo</text>'
157
            '<severity>5.5</severity>'
158
            '</modify_note>'
159
        )
160
161
        self.gmp.modify_note(note_id='n1', text='foo', severity=Decimal(5.5))
162
163
        self.connection.send.has_been_called_with(
164
            '<modify_note note_id="n1">'
165
            '<text>foo</text>'
166
            '<severity>5.5</severity>'
167
            '</modify_note>'
168
        )
169
170
    def test_modify_note_with_threat(self):
171
        self.gmp.modify_note(
172
            note_id='n1', text='foo', threat=SeverityLevel.HIGH
173
        )
174
175
        self.connection.send.has_been_called_with(
176
            '<modify_note note_id="n1">' '<text>foo</text>' '</modify_note>'
177
        )
178
179
180
if __name__ == '__main__':
181
    unittest.main()
182