Passed
Pull Request — master (#87)
by
unknown
03:06
created

tests.protocols.gmpv7.test_modify_config_set_nvt_selection   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 179
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 90
dl 0
loc 179
rs 10
c 0
b 0
f 0
wmc 14

5 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpModifyConfigSetNvtSelectionTestCase.setUp() 0 3 1
A GmpModifyConfigSetNvtSelectionTestCase.test_modify_config_set_nvt_selection_invalid_nvt_oids() 0 20 4
A GmpModifyConfigSetNvtSelectionTestCase.test_modify_config_set_nvt_selection_missing_family() 0 20 4
A GmpModifyConfigSetNvtSelectionTestCase.test_modify_config_set_nvt_selection_missing_config_id() 0 20 4
A GmpModifyConfigSetNvtSelectionTestCase.test_modify_config_set_nvt_selection() 0 71 1
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, InvalidArgument
22
from gvm.protocols.gmpv7 import Gmp
23
24
from .. import MockConnection
25
26
27
class GmpModifyConfigSetNvtSelectionTestCase(unittest.TestCase):
28
29
    def setUp(self):
30
        self.connection = MockConnection()
31
        self.gmp = Gmp(self.connection)
32
33
    def test_modify_config_set_nvt_selection(self):
34
        self.gmp.modify_config_set_nvt_selection(
35
            config_id='c1',
36
            family='foo',
37
            nvt_oids=['o1']
38
        )
39
40
        self.connection.send.has_been_called_with(
41
            '<modify_config config_id="c1">'
42
            '<nvt_selection>'
43
            '<family>foo</family>'
44
            '<nvt oid="o1"/>'
45
            '</nvt_selection>'
46
            '</modify_config>'
47
        )
48
49
        self.gmp.modify_config_set_nvt_selection(
50
            config_id='c1',
51
            family='foo',
52
            nvt_oids=['o1', 'o2']
53
        )
54
55
        self.connection.send.has_been_called_with(
56
            '<modify_config config_id="c1">'
57
            '<nvt_selection>'
58
            '<family>foo</family>'
59
            '<nvt oid="o1"/>'
60
            '<nvt oid="o2"/>'
61
            '</nvt_selection>'
62
            '</modify_config>'
63
        )
64
65
        self.gmp.modify_config_set_nvt_selection(
66
            'c1',
67
            'foo',
68
            ['o1']
69
        )
70
71
        self.connection.send.has_been_called_with(
72
            '<modify_config config_id="c1">'
73
            '<nvt_selection>'
74
            '<family>foo</family>'
75
            '<nvt oid="o1"/>'
76
            '</nvt_selection>'
77
            '</modify_config>'
78
        )
79
80
        self.gmp.modify_config_set_nvt_selection(
81
            'c1',
82
            'foo',
83
            ('o1', 'o2'),
84
        )
85
86
        self.connection.send.has_been_called_with(
87
            '<modify_config config_id="c1">'
88
            '<nvt_selection>'
89
            '<family>foo</family>'
90
            '<nvt oid="o1"/>'
91
            '<nvt oid="o2"/>'
92
            '</nvt_selection>'
93
            '</modify_config>'
94
        )
95
96
        self.gmp.modify_config_set_nvt_selection(
97
            config_id='c1',
98
            family='foo',
99
            nvt_oids=[]
100
        )
101
102
        self.connection.send.has_been_called_with(
103
            '<modify_config config_id="c1">'
104
            '<nvt_selection>'
105
            '<family>foo</family>'
106
            '</nvt_selection>'
107
            '</modify_config>'
108
        )
109
110
    def test_modify_config_set_nvt_selection_missing_config_id(self):
111
        with self.assertRaises(RequiredArgument):
112
            self.gmp.modify_config_set_nvt_selection(
113
                config_id=None,
114
                family='foo',
115
                nvt_oids=['o1']
116
            )
117
118
        with self.assertRaises(RequiredArgument):
119
            self.gmp.modify_config_set_nvt_selection(
120
                config_id='',
121
                family='foo',
122
                nvt_oids=['o1']
123
            )
124
125
        with self.assertRaises(RequiredArgument):
126
            self.gmp.modify_config_set_nvt_selection(
127
                '',
128
                'foo',
129
                ['o1']
130
            )
131
132
    def test_modify_config_set_nvt_selection_missing_family(self):
133
        with self.assertRaises(RequiredArgument):
134
            self.gmp.modify_config_set_nvt_selection(
135
                config_id='c1',
136
                family=None,
137
                nvt_oids=['o1']
138
            )
139
140
        with self.assertRaises(RequiredArgument):
141
            self.gmp.modify_config_set_nvt_selection(
142
                config_id='c1',
143
                family='',
144
                nvt_oids=['o1']
145
            )
146
147
        with self.assertRaises(RequiredArgument):
148
            self.gmp.modify_config_set_nvt_selection(
149
                'c1',
150
                '',
151
                ['o1']
152
            )
153
154
    def test_modify_config_set_nvt_selection_invalid_nvt_oids(self):
155
        with self.assertRaises(InvalidArgument):
156
            self.gmp.modify_config_set_nvt_selection(
157
                config_id='c1',
158
                family='foo',
159
                nvt_oids=None
160
            )
161
162
        with self.assertRaises(InvalidArgument):
163
            self.gmp.modify_config_set_nvt_selection(
164
                config_id='c1',
165
                family='foo',
166
                nvt_oids='',
167
            )
168
169
        with self.assertRaises(InvalidArgument):
170
            self.gmp.modify_config_set_nvt_selection(
171
                'c1',
172
                'foo',
173
                ''
174
            )
175
176
177
if __name__ == '__main__':
178
    unittest.main()
179