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

tests.protocols.gmpv7.test_modify_config_set_scanner_preference   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 58
dl 0
loc 120
rs 10
c 0
b 0
f 0
wmc 11

5 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpModifyConfigSetScannerPreferenceTestCase.test_modify_config_set_scanner_pref() 0 21 1
A GmpModifyConfigSetScannerPreferenceTestCase.test_modify_config_scanner_pref_missing_name() 0 20 4
A GmpModifyConfigSetScannerPreferenceTestCase.test_modify_config_set_comment_missing_config_id() 0 17 4
A GmpModifyConfigSetScannerPreferenceTestCase.setUp() 0 3 1
A GmpModifyConfigSetScannerPreferenceTestCase.test_modify_config_set_scanner_pref_with_value() 0 9 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
22
from gvm.protocols.gmpv7 import Gmp
23
24
from .. import MockConnection
25
26
27
class GmpModifyConfigSetScannerPreferenceTestCase(unittest.TestCase):
28
29
    def setUp(self):
30
        self.connection = MockConnection()
31
        self.gmp = Gmp(self.connection)
32
33
    def test_modify_config_set_scanner_pref(self):
34
        self.gmp.modify_config_set_scanner_preference(
35
            config_id='c1',
36
            name='foo',
37
        )
38
39
        self.connection.send.has_been_called_with(
40
            '<modify_config config_id="c1">'
41
            '<preference>'
42
            '<name>foo</name>'
43
            '</preference>'
44
            '</modify_config>'
45
        )
46
47
        self.gmp.modify_config_set_scanner_preference(
48
            'c1',
49
            'foo',
50
        )
51
52
        self.connection.send.has_been_called_with(
53
            '<modify_config config_id="c1">'
54
            '<preference>'
55
            '<name>foo</name>'
56
            '</preference>'
57
            '</modify_config>'
58
        )
59
60
    def test_modify_config_set_scanner_pref_with_value(self):
61
        self.gmp.modify_config_set_scanner_preference(
62
            'c1',
63
            'foo',
64
            value='bar',
65
        )
66
67
        self.connection.send.has_been_called_with(
68
            '<modify_config config_id="c1">'
69
            '<preference>'
70
            '<name>foo</name>'
71
            '<value>YmFy</value>'
72
            '</preference>'
73
            '</modify_config>'
74
        )
75
76
    def test_modify_config_scanner_pref_missing_name(self):
77
        with self.assertRaises(RequiredArgument):
78
            self.gmp.modify_config_set_scanner_preference(
79
                'c1',
80
                name=None,
81
                value='bar',
82
            )
83
84
        with self.assertRaises(RequiredArgument):
85
            self.gmp.modify_config_set_scanner_preference(
86
                'c1',
87
                name='',
88
                value='bar',
89
            )
90
91
        with self.assertRaises(RequiredArgument):
92
            self.gmp.modify_config_set_scanner_preference(
93
                'c1',
94
                '',
95
                value='bar',
96
            )
97
98
    def test_modify_config_set_comment_missing_config_id(self):
99
        with self.assertRaises(RequiredArgument):
100
            self.gmp.modify_config_set_scanner_preference(
101
                config_id=None,
102
                name='foo',
103
            )
104
105
        with self.assertRaises(RequiredArgument):
106
            self.gmp.modify_config_set_scanner_preference(
107
                '',
108
                'foo',
109
            )
110
111
        with self.assertRaises(RequiredArgument):
112
            self.gmp.modify_config_set_scanner_preference(
113
                config_id='',
114
                name='foo',
115
            )
116
117
118
if __name__ == '__main__':
119
    unittest.main()
120