Completed
Push — master ( f3cde9...b114e7 )
by
unknown
13s queued 11s
created

tests.protocols.gmpv7.test_modify_config   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 183
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 92
dl 0
loc 183
rs 10
c 0
b 0
f 0
wmc 18

8 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpModifyConfigTestCase.test_modify_config_set_nvt_pref() 0 16 2
A GmpModifyConfigTestCase.test_modify_config_invalid_selection() 0 11 3
A GmpModifyConfigTestCase.test_modify_config_set_family_selection() 0 15 2
A GmpModifyConfigTestCase.test_modify_config_set_nvt_selection() 0 16 2
A GmpModifyConfigTestCase.setUp() 0 3 1
A GmpModifyConfigTestCase.test_modify_config_set_scanner_pref() 0 16 2
A GmpModifyConfigTestCase.test_modify_config_set_comment() 0 15 2
A GmpModifyConfigTestCase.test_modify_config_missing_config_id() 0 17 4
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
import warnings
21
22
from gvm.errors import RequiredArgument, InvalidArgument
23
from gvm.protocols.gmpv7 import Gmp
24
25
from .. import MockConnection
26
27
28
class GmpModifyConfigTestCase(unittest.TestCase):
29
30
    def setUp(self):
31
        self.connection = MockConnection()
32
        self.gmp = Gmp(self.connection)
33
34
    def test_modify_config_invalid_selection(self):
35
        with self.assertRaises(InvalidArgument):
36
            self.gmp.modify_config(
37
                config_id='c1',
38
                selection='foo',
39
            )
40
41
        with self.assertRaises(InvalidArgument):
42
            self.gmp.modify_config(
43
                config_id='c1',
44
                selection='',
45
            )
46
47
    def test_modify_config_missing_config_id(self):
48
        with self.assertRaises(RequiredArgument):
49
            self.gmp.modify_config(
50
                config_id=None,
51
                selection='nvt_pref',
52
            )
53
54
        with self.assertRaises(RequiredArgument):
55
            self.gmp.modify_config(
56
                config_id='',
57
                selection='nvt_pref',
58
            )
59
60
        with self.assertRaises(RequiredArgument):
61
            self.gmp.modify_config(
62
                '',
63
                selection='nvt_pref',
64
            )
65
66
    def test_modify_config_set_comment(self):
67
        with warnings.catch_warnings(record=True) as w:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "w" doesn't conform to '[a-z_][a-z0-9_]+$' pattern ('[a-z_][a-z0-9_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
68
            warnings.simplefilter("always")
69
70
            self.gmp.modify_config(
71
                config_id='c1',
72
                selection=None,
73
                comment='foo'
74
            )
75
76
            self.assertEqual(len(w), 1)
77
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))
78
79
        self.connection.send.has_been_called_with(
80
            '<modify_config config_id="c1">'
81
            '<comment>foo</comment>'
82
            '</modify_config>'
83
        )
84
85
    def test_modify_config_set_nvt_pref(self):
86
        with warnings.catch_warnings(record=True) as w:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "w" doesn't conform to '[a-z_][a-z0-9_]+$' pattern ('[a-z_][a-z0-9_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
87
            warnings.simplefilter("always")
88
89
            self.gmp.modify_config(
90
                config_id='c1',
91
                selection='nvt_pref',
92
                nvt_oid='o1',
93
                name='foo',
94
            )
95
96
            self.assertEqual(len(w), 1)
97
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))
98
99
        self.connection.send.has_been_called_with(
100
            '<modify_config config_id="c1">'
101
            '<preference>'
102
            '<nvt oid="o1"/>'
103
            '<name>foo</name>'
104
            '</preference>'
105
            '</modify_config>'
106
        )
107
108
    def test_modify_config_set_scanner_pref(self):
109
        with warnings.catch_warnings(record=True) as w:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "w" doesn't conform to '[a-z_][a-z0-9_]+$' pattern ('[a-z_][a-z0-9_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
110
            warnings.simplefilter("always")
111
112
            self.gmp.modify_config(
113
                config_id='c1',
114
                selection='scan_pref',
115
                name='foo',
116
                value='bar',
117
            )
118
119
            self.assertEqual(len(w), 1)
120
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))
121
122
        self.connection.send.has_been_called_with(
123
            '<modify_config config_id="c1">'
124
            '<preference>'
125
            '<name>foo</name>'
126
            '<value>YmFy</value>'
127
            '</preference>'
128
            '</modify_config>'
129
        )
130
131
    def test_modify_config_set_nvt_selection(self):
132
        with warnings.catch_warnings(record=True) as w:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "w" doesn't conform to '[a-z_][a-z0-9_]+$' pattern ('[a-z_][a-z0-9_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
133
            warnings.simplefilter("always")
134
135
            self.gmp.modify_config(
136
                config_id='c1',
137
                selection='nvt_selection',
138
                nvt_oids=['o1'],
139
                family='foo',
140
            )
141
142
            self.assertEqual(len(w), 1)
143
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))
144
145
        self.connection.send.has_been_called_with(
146
            '<modify_config config_id="c1">'
147
            '<nvt_selection>'
148
            '<family>foo</family>'
149
            '<nvt oid="o1"/>'
150
            '</nvt_selection>'
151
            '</modify_config>'
152
        )
153
154
    def test_modify_config_set_family_selection(self):
155
        with warnings.catch_warnings(record=True) as w:
0 ignored issues
show
Coding Style Naming introduced by
Variable name "w" doesn't conform to '[a-z_][a-z0-9_]+$' pattern ('[a-z_][a-z0-9_]+$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
156
            warnings.simplefilter("always")
157
158
            self.gmp.modify_config(
159
                config_id='c1',
160
                selection='family_selection',
161
                families=['foo'],
162
            )
163
164
            self.assertEqual(len(w), 1)
165
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))
166
167
        self.connection.send.has_been_called_with(
168
            '<modify_config config_id="c1">'
169
            '<family_selection>'
170
            '<growing>1</growing>'
171
            '<family>'
172
            '<name>foo</name>'
173
            '<all>1</all>'
174
            '<growing>1</growing>'
175
            '</family>'
176
            '</family_selection>'
177
            '</modify_config>'
178
        )
179
180
181
if __name__ == '__main__':
182
    unittest.main()
183