|
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 gmp.xml import _GmpCommandFactory as GmpCommandFactory |
|
22
|
|
|
|
|
23
|
|
|
|
|
24
|
|
|
class GMPCreateReportCommandTestCase(unittest.TestCase): |
|
|
|
|
|
|
25
|
|
|
|
|
26
|
|
|
TASK_ID = '00000000-0000-0000-0000-000000000001' |
|
27
|
|
|
TASK_NAME = 'unit test task' |
|
28
|
|
|
COMMENT = 'This is a comment' |
|
29
|
|
|
REPORT_XML_STRING = ( |
|
30
|
|
|
'<report id="67a62fb7-b238-4f0e-bc48-59bde8939cdc">' |
|
31
|
|
|
'<results max="1" start="1">' |
|
32
|
|
|
'<result id="f180b40f-49dd-4856-81ed-8c1195afce80">' |
|
33
|
|
|
'<severity>0.0</severity>' |
|
34
|
|
|
'<nvt oid="1.3.6.1.4.1.25623.1.0.10330"/>' |
|
35
|
|
|
'<host>132.67.253.114</host>' |
|
36
|
|
|
'</result></results></report>' |
|
37
|
|
|
) |
|
38
|
|
|
|
|
39
|
|
|
def setUp(self): |
|
40
|
|
|
self.gmp = GmpCommandFactory() |
|
41
|
|
|
|
|
42
|
|
|
def tearDown(self): |
|
43
|
|
|
pass |
|
44
|
|
|
|
|
45
|
|
|
def test_create_report_cmd_task_id(self): |
|
|
|
|
|
|
46
|
|
|
cmd = self.gmp.create_report_command( |
|
47
|
|
|
self.REPORT_XML_STRING, |
|
48
|
|
|
{ |
|
49
|
|
|
'task_id': self.TASK_ID, |
|
50
|
|
|
}) |
|
51
|
|
|
|
|
52
|
|
|
self.assertEqual( |
|
53
|
|
|
'<create_report>' |
|
54
|
|
|
'<task id="{0}"/>' |
|
55
|
|
|
'{1}' |
|
56
|
|
|
'</create_report>'.format(self.TASK_ID, self.REPORT_XML_STRING), |
|
57
|
|
|
cmd) |
|
58
|
|
|
|
|
59
|
|
|
def test_create_teport_cmd_task_name(self): |
|
|
|
|
|
|
60
|
|
|
cmd = self.gmp.create_report_command( |
|
61
|
|
|
self.REPORT_XML_STRING, |
|
62
|
|
|
{ |
|
63
|
|
|
'task_name': self.TASK_NAME, |
|
64
|
|
|
'comment': self.COMMENT, |
|
65
|
|
|
}) |
|
66
|
|
|
|
|
67
|
|
|
self.assertEqual( |
|
68
|
|
|
'<create_report>' |
|
69
|
|
|
'<task>' |
|
70
|
|
|
'<name>{0}</name>' |
|
71
|
|
|
'<comment>{1}</comment>' |
|
72
|
|
|
'</task>' |
|
73
|
|
|
'{2}' |
|
74
|
|
|
'</create_report>'.format(self.TASK_NAME, self.COMMENT, |
|
75
|
|
|
self.REPORT_XML_STRING), |
|
76
|
|
|
cmd) |
|
77
|
|
|
|
|
78
|
|
|
def test_create_report_cmd_noreport(self): |
|
|
|
|
|
|
79
|
|
|
args = { |
|
80
|
|
|
'task_name': self.TASK_NAME, |
|
81
|
|
|
'comment': self.COMMENT, |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
self.assertRaises(ValueError, |
|
85
|
|
|
self.gmp.create_report_command, |
|
86
|
|
|
None, |
|
87
|
|
|
args) |
|
88
|
|
|
|
|
89
|
|
|
def test_create_report_cmd_notask(self): |
|
|
|
|
|
|
90
|
|
|
args = {'comment': self.COMMENT} |
|
91
|
|
|
self.assertRaises(ValueError, |
|
92
|
|
|
self.gmp.create_report_command, |
|
93
|
|
|
self.REPORT_XML_STRING, |
|
94
|
|
|
args) |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
if __name__ == '__main__': |
|
98
|
|
|
unittest.main() |
|
99
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.