|
1
|
|
|
# -*- coding: utf-8 -*- |
|
2
|
|
|
# Copyright (C) 2018 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 gvm.errors import RequiredArgument |
|
22
|
|
|
from gvm.protocols.gmpv208 import ( |
|
23
|
|
|
ReportFormatType, |
|
24
|
|
|
get_report_format_id_from_string, |
|
25
|
|
|
) |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
View Code Duplication |
class GmpModifyReportFormatTestCase: |
|
|
|
|
|
|
29
|
|
|
def test_modify_report_format(self): |
|
30
|
|
|
self.gmp.modify_report_format(report_format_id='rf1') |
|
31
|
|
|
|
|
32
|
|
|
self.connection.send.has_been_called_with( |
|
33
|
|
|
'<modify_report_format report_format_id="rf1"/>' |
|
34
|
|
|
) |
|
35
|
|
|
|
|
36
|
|
|
def test_modify_report_format_missing_report_format_id(self): |
|
37
|
|
|
with self.assertRaises(RequiredArgument): |
|
38
|
|
|
self.gmp.modify_report_format(report_format_id=None) |
|
39
|
|
|
|
|
40
|
|
|
with self.assertRaises(RequiredArgument): |
|
41
|
|
|
self.gmp.modify_report_format(report_format_id='') |
|
42
|
|
|
|
|
43
|
|
|
with self.assertRaises(RequiredArgument): |
|
44
|
|
|
self.gmp.modify_report_format('') |
|
45
|
|
|
|
|
46
|
|
|
def test_modify_report_format_with_summary(self): |
|
47
|
|
|
self.gmp.modify_report_format(report_format_id='rf1', summary='foo') |
|
48
|
|
|
|
|
49
|
|
|
self.connection.send.has_been_called_with( |
|
50
|
|
|
'<modify_report_format report_format_id="rf1">' |
|
51
|
|
|
'<summary>foo</summary>' |
|
52
|
|
|
'</modify_report_format>' |
|
53
|
|
|
) |
|
54
|
|
|
|
|
55
|
|
|
def test_modify_report_format_with_name(self): |
|
56
|
|
|
self.gmp.modify_report_format(report_format_id='rf1', name='foo') |
|
57
|
|
|
|
|
58
|
|
|
self.connection.send.has_been_called_with( |
|
59
|
|
|
'<modify_report_format report_format_id="rf1">' |
|
60
|
|
|
'<name>foo</name>' |
|
61
|
|
|
'</modify_report_format>' |
|
62
|
|
|
) |
|
63
|
|
|
|
|
64
|
|
|
def test_modify_report_format_with_name_and_type(self): |
|
65
|
|
|
self.gmp.modify_report_format( |
|
66
|
|
|
report_format_id=ReportFormatType.XML, name='foo' |
|
67
|
|
|
) |
|
68
|
|
|
|
|
69
|
|
|
report_format_id = get_report_format_id_from_string('xml').value |
|
70
|
|
|
self.connection.send.has_been_called_with( |
|
71
|
|
|
'<modify_report_format report_format_id="{}">' |
|
72
|
|
|
'<name>foo</name>' |
|
73
|
|
|
'</modify_report_format>'.format(report_format_id) |
|
74
|
|
|
) |
|
75
|
|
|
|
|
76
|
|
|
def test_modify_report_format_with_active(self): |
|
77
|
|
|
self.gmp.modify_report_format(report_format_id='rf1', active=True) |
|
78
|
|
|
|
|
79
|
|
|
self.connection.send.has_been_called_with( |
|
80
|
|
|
'<modify_report_format report_format_id="rf1">' |
|
81
|
|
|
'<active>1</active>' |
|
82
|
|
|
'</modify_report_format>' |
|
83
|
|
|
) |
|
84
|
|
|
|
|
85
|
|
|
self.gmp.modify_report_format(report_format_id='rf1', active=False) |
|
86
|
|
|
|
|
87
|
|
|
self.connection.send.has_been_called_with( |
|
88
|
|
|
'<modify_report_format report_format_id="rf1">' |
|
89
|
|
|
'<active>0</active>' |
|
90
|
|
|
'</modify_report_format>' |
|
91
|
|
|
) |
|
92
|
|
|
|
|
93
|
|
|
def test_modify_report_format_with_param_name(self): |
|
94
|
|
|
self.gmp.modify_report_format(report_format_id='rf1', param_name='foo') |
|
95
|
|
|
|
|
96
|
|
|
self.connection.send.has_been_called_with( |
|
97
|
|
|
'<modify_report_format report_format_id="rf1">' |
|
98
|
|
|
'<param>' |
|
99
|
|
|
'<name>foo</name>' |
|
100
|
|
|
'</param>' |
|
101
|
|
|
'</modify_report_format>' |
|
102
|
|
|
) |
|
103
|
|
|
|
|
104
|
|
|
def test_modify_report_format_with_param_name_and_value(self): |
|
105
|
|
|
self.gmp.modify_report_format( |
|
106
|
|
|
report_format_id='rf1', param_name='foo', param_value='bar' |
|
107
|
|
|
) |
|
108
|
|
|
|
|
109
|
|
|
self.connection.send.has_been_called_with( |
|
110
|
|
|
'<modify_report_format report_format_id="rf1">' |
|
111
|
|
|
'<param>' |
|
112
|
|
|
'<name>foo</name>' |
|
113
|
|
|
'<value>bar</value>' |
|
114
|
|
|
'</param>' |
|
115
|
|
|
'</modify_report_format>' |
|
116
|
|
|
) |
|
117
|
|
|
|
|
118
|
|
|
self.gmp.modify_report_format( |
|
119
|
|
|
report_format_id='rf1', param_name='foo', param_value='' |
|
120
|
|
|
) |
|
121
|
|
|
|
|
122
|
|
|
self.connection.send.has_been_called_with( |
|
123
|
|
|
'<modify_report_format report_format_id="rf1">' |
|
124
|
|
|
'<param>' |
|
125
|
|
|
'<name>foo</name>' |
|
126
|
|
|
'<value></value>' |
|
127
|
|
|
'</param>' |
|
128
|
|
|
'</modify_report_format>' |
|
129
|
|
|
) |
|
130
|
|
|
|
|
131
|
|
|
|
|
132
|
|
|
if __name__ == '__main__': |
|
133
|
|
|
unittest.main() |
|
134
|
|
|
|