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

tests.protocols.gmpv7.test_modify_config_set_nvt_preference   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 86
dl 0
loc 157
rs 10
c 0
b 0
f 0
wmc 15

6 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpModifyConfigSetNvtPreferenceTestCase.test_modify_config_set_comment_missing_config_id() 0 20 4
A GmpModifyConfigSetNvtPreferenceTestCase.test_modify_config_nvt_pref_missing_name() 0 23 4
A GmpModifyConfigSetNvtPreferenceTestCase.test_modify_config_set_nvt_pref() 0 24 1
A GmpModifyConfigSetNvtPreferenceTestCase.test_modify_config_set_nvt_pref_missing_nvt_oid() 0 23 4
A GmpModifyConfigSetNvtPreferenceTestCase.test_modify_config_set_nvt_pref_with_value() 0 10 1
A GmpModifyConfigSetNvtPreferenceTestCase.setUp() 0 3 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 GmpModifyConfigSetNvtPreferenceTestCase(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_pref(self):
34
        self.gmp.modify_config_set_nvt_preference(
35
            config_id='c1',
36
            nvt_oid='o1',
37
            name='foo',
38
        )
39
40
        self.connection.send.has_been_called_with(
41
            '<modify_config config_id="c1">'
42
            '<preference>'
43
            '<nvt oid="o1"/>'
44
            '<name>foo</name>'
45
            '</preference>'
46
            '</modify_config>'
47
        )
48
49
        self.gmp.modify_config_set_nvt_preference(
50
            'c1',
51
            'foo',
52
            'o1',
53
        )
54
55
        self.connection.send.has_been_called_with(
56
            '<modify_config config_id="c1">'
57
            '<preference>'
58
            '<nvt oid="o1"/>'
59
            '<name>foo</name>'
60
            '</preference>'
61
            '</modify_config>'
62
        )
63
64
    def test_modify_config_set_nvt_pref_with_value(self):
65
        self.gmp.modify_config_set_nvt_preference(
66
            'c1',
67
            'foo',
68
            nvt_oid='o1',
69
            value='bar',
70
        )
71
72
        self.connection.send.has_been_called_with(
73
            '<modify_config config_id="c1">'
74
            '<preference>'
75
            '<nvt oid="o1"/>'
76
            '<name>foo</name>'
77
            '<value>YmFy</value>'
78
            '</preference>'
79
            '</modify_config>'
80
        )
81
82
    def test_modify_config_set_nvt_pref_missing_nvt_oid(self):
83
        with self.assertRaises(RequiredArgument):
84
            self.gmp.modify_config_set_nvt_preference(
85
                'c1',
86
                'foo',
87
                nvt_oid=None,
88
                value='bar',
89
            )
90
91
        with self.assertRaises(RequiredArgument):
92
            self.gmp.modify_config_set_nvt_preference(
93
                'c1',
94
                'foo',
95
                nvt_oid='',
96
                value='bar',
97
            )
98
99
        with self.assertRaises(RequiredArgument):
100
            self.gmp.modify_config_set_nvt_preference(
101
                'c1',
102
                'foo',
103
                '',
104
                value='bar',
105
            )
106
107
    def test_modify_config_nvt_pref_missing_name(self):
108
        with self.assertRaises(RequiredArgument):
109
            self.gmp.modify_config_set_nvt_preference(
110
                'c1',
111
                name=None,
112
                nvt_oid='o1',
113
                value='bar',
114
            )
115
116
        with self.assertRaises(RequiredArgument):
117
            self.gmp.modify_config_set_nvt_preference(
118
                'c1',
119
                name='',
120
                nvt_oid='o1',
121
                value='bar',
122
            )
123
124
        with self.assertRaises(RequiredArgument):
125
            self.gmp.modify_config_set_nvt_preference(
126
                'c1',
127
                '',
128
                nvt_oid='o1',
129
                value='bar',
130
            )
131
132
    def test_modify_config_set_comment_missing_config_id(self):
133
        with self.assertRaises(RequiredArgument):
134
            self.gmp.modify_config_set_nvt_preference(
135
                config_id=None,
136
                name='foo',
137
                nvt_oid='o1',
138
            )
139
140
        with self.assertRaises(RequiredArgument):
141
            self.gmp.modify_config_set_nvt_preference(
142
                '',
143
                'foo',
144
                'o1',
145
            )
146
147
        with self.assertRaises(RequiredArgument):
148
            self.gmp.modify_config_set_nvt_preference(
149
                config_id='',
150
                name='foo',
151
                nvt_oid='o1',
152
            )
153
154
155
if __name__ == '__main__':
156
    unittest.main()
157