Completed
Push — master ( a4987b...bdfb6a )
by Björn
28s queued 14s
created

tests.protocols.gmpv208.entities.reports.test_import_report   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 39
dl 0
loc 93
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpImportReportTestMixin.test_import_report_missing_task() 0 3 2
A GmpImportReportTestMixin.test_import_report_missing_report() 0 6 3
A GmpImportReportTestMixin.test_import_report_invalid_xml() 0 7 3
A GmpImportReportTestMixin.test_import_report_with_task_id() 0 9 1
A GmpImportReportTestMixin.test_import_report_with_in_assets() 0 26 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, InvalidArgument
20
21
22
class GmpImportReportTestMixin:
23
24
    TASK_ID = '00000000-0000-0000-0000-000000000001'
25
    REPORT_XML_STRING = (
26
        '<report id="67a62fb7-b238-4f0e-bc48-59bde8939cdc">'
27
        '<results max="1" start="1">'
28
        '<result id="f180b40f-49dd-4856-81ed-8c1195afce80">'
29
        '<severity>0.0</severity>'
30
        '<nvt oid="1.3.6.1.4.1.25623.1.0.10330"/>'
31
        '<host>132.67.253.114</host>'
32
        '</result></results></report>'
33
    )
34
35
    def test_import_report_with_task_id(self):
36
        self.gmp.import_report(self.REPORT_XML_STRING, task_id=self.TASK_ID)
37
38
        self.connection.send.has_been_called_with(
39
            '<create_report>'
40
            '<task id="{task}"/>'
41
            '{report}'
42
            '</create_report>'.format(
43
                task=self.TASK_ID, report=self.REPORT_XML_STRING
44
            )
45
        )
46
47
    def test_import_report_missing_report(self):
48
        with self.assertRaises(RequiredArgument):
49
            self.gmp.import_report(None, task_id=self.TASK_ID)
50
51
        with self.assertRaises(RequiredArgument):
52
            self.gmp.import_report('', task_id=self.TASK_ID)
53
54
    def test_import_report_missing_task(self):
55
        with self.assertRaises(RequiredArgument):
56
            self.gmp.import_report(self.REPORT_XML_STRING)
57
58
    def test_import_report_invalid_xml(self):
59
        with self.assertRaises(InvalidArgument):
60
            self.gmp.import_report('Foo', task_id=self.TASK_ID)  # not root tag
61
62
        with self.assertRaises(InvalidArgument):
63
            self.gmp.import_report(
64
                '<Foo>', task_id=self.TASK_ID  # missing closing tag
65
            )
66
67
    def test_import_report_with_in_assets(self):
68
        self.gmp.import_report(
69
            self.REPORT_XML_STRING, task_id=self.TASK_ID, in_assets=False
70
        )
71
72
        self.connection.send.has_been_called_with(
73
            '<create_report>'
74
            '<task id="{task}"/>'
75
            '<in_assets>0</in_assets>'
76
            '{report}'
77
            '</create_report>'.format(
78
                task=self.TASK_ID, report=self.REPORT_XML_STRING
79
            )
80
        )
81
82
        self.gmp.import_report(
83
            self.REPORT_XML_STRING, task_id=self.TASK_ID, in_assets=True
84
        )
85
86
        self.connection.send.has_been_called_with(
87
            '<create_report>'
88
            '<task id="{task}"/>'
89
            '<in_assets>1</in_assets>'
90
            '{report}'
91
            '</create_report>'.format(
92
                task=self.TASK_ID, report=self.REPORT_XML_STRING
93
            )
94
        )
95