Passed
Pull Request — master (#466)
by Jaspar
254:58 queued 196:16
created

GmpModifyScannerTestMixin.test_modify_scanner_with_comment()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 1
dl 5
loc 5
rs 10
c 0
b 0
f 0
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, InvalidArgumentType
20
from gvm.protocols.gmpv208 import ScannerType
21
22
23 View Code Duplication
class GmpModifyScannerTestMixin:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
24
    def test_modify_scanner(self):
25
        self.gmp.modify_scanner(scanner_id='s1')
26
27
        self.connection.send.has_been_called_with(
28
            '<modify_scanner scanner_id="s1"/>'
29
        )
30
31
    def test_modify_scanner_missing_scanner_id(self):
32
        with self.assertRaises(RequiredArgument):
33
            self.gmp.modify_scanner(scanner_id=None)
34
35
        with self.assertRaises(RequiredArgument):
36
            self.gmp.modify_scanner(scanner_id='')
37
38
    def test_modify_scanner_with_comment(self):
39
        self.gmp.modify_scanner(scanner_id='s1', comment='foo')
40
41
        self.connection.send.has_been_called_with(
42
            '<modify_scanner scanner_id="s1">'
43
            '<comment>foo</comment>'
44
            '</modify_scanner>'
45
        )
46
47
    def test_modify_scanner_with_host(self):
48
        self.gmp.modify_scanner(scanner_id='s1', host='foo')
49
50
        self.connection.send.has_been_called_with(
51
            '<modify_scanner scanner_id="s1">'
52
            '<host>foo</host>'
53
            '</modify_scanner>'
54
        )
55
56
    def test_modify_scanner_with_port(self):
57
        self.gmp.modify_scanner(scanner_id='s1', port=1234)
58
59
        self.connection.send.has_been_called_with(
60
            '<modify_scanner scanner_id="s1">'
61
            '<port>1234</port>'
62
            '</modify_scanner>'
63
        )
64
65
        self.gmp.modify_scanner(scanner_id='s1', port='1234')
66
67
        self.connection.send.has_been_called_with(
68
            '<modify_scanner scanner_id="s1">'
69
            '<port>1234</port>'
70
            '</modify_scanner>'
71
        )
72
73
    def test_modify_scanner_with_name(self):
74
        self.gmp.modify_scanner(scanner_id='s1', name='foo')
75
76
        self.connection.send.has_been_called_with(
77
            '<modify_scanner scanner_id="s1">'
78
            '<name>foo</name>'
79
            '</modify_scanner>'
80
        )
81
82
    def test_modify_scanner_with_ca_pub(self):
83
        self.gmp.modify_scanner(scanner_id='s1', ca_pub='foo')
84
85
        self.connection.send.has_been_called_with(
86
            '<modify_scanner scanner_id="s1">'
87
            '<ca_pub>foo</ca_pub>'
88
            '</modify_scanner>'
89
        )
90
91
    def test_modify_scanner_with_credential_id(self):
92
        self.gmp.modify_scanner(scanner_id='s1', credential_id='c1')
93
94
        self.connection.send.has_been_called_with(
95
            '<modify_scanner scanner_id="s1">'
96
            '<credential id="c1"/>'
97
            '</modify_scanner>'
98
        )
99
100
    def test_modify_scanner_with_scanner_type(self):
101
        self.gmp.modify_scanner(
102
            scanner_id='s1', scanner_type=ScannerType.OSP_SCANNER_TYPE
103
        )
104
105
        self.connection.send.has_been_called_with(
106
            '<modify_scanner scanner_id="s1">'
107
            '<type>1</type>'
108
            '</modify_scanner>'
109
        )
110
111
        self.gmp.modify_scanner(
112
            scanner_id='s1', scanner_type=ScannerType.OPENVAS_SCANNER_TYPE
113
        )
114
115
        self.connection.send.has_been_called_with(
116
            '<modify_scanner scanner_id="s1">'
117
            '<type>2</type>'
118
            '</modify_scanner>'
119
        )
120
121
        self.gmp.modify_scanner(
122
            scanner_id='s1', scanner_type=ScannerType.CVE_SCANNER_TYPE
123
        )
124
125
        self.connection.send.has_been_called_with(
126
            '<modify_scanner scanner_id="s1">'
127
            '<type>3</type>'
128
            '</modify_scanner>'
129
        )
130
131
        self.gmp.modify_scanner(
132
            scanner_id='s1', scanner_type=ScannerType.GMP_SCANNER_TYPE
133
        )
134
135
        self.connection.send.has_been_called_with(
136
            '<modify_scanner scanner_id="s1">'
137
            '<type>4</type>'
138
            '</modify_scanner>'
139
        )
140
141
    def test_modify_scanner_invalid_scanner_type(self):
142
        with self.assertRaises(InvalidArgumentType):
143
            self.gmp.modify_scanner(scanner_id='s1', scanner_type='')
144
145
        with self.assertRaises(InvalidArgumentType):
146
            self.gmp.modify_scanner(scanner_id='s1', scanner_type='-1')
147
148
        with self.assertRaises(InvalidArgumentType):
149
            self.gmp.modify_scanner(scanner_id='s1', scanner_type=1)
150