Passed
Push — master ( 1e243f...b519bb )
by Björn
197:44 queued 153:47
created

tests.protocols.gmpv208.entities.policies.test_modify_policy_set_nvt_selection   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 127
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 127
rs 10
c 0
b 0
f 0
wmc 13

4 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpModifyPolicySetNvtSelectionTestMixin.test_modify_policy_set_nvt_selection() 0 57 1
A GmpModifyPolicySetNvtSelectionTestMixin.test_modify_policy_set_nvt_selection_invalid_nvt_oids() 0 13 4
A GmpModifyPolicySetNvtSelectionTestMixin.test_modify_policy_set_nvt_selection_missing_config_id() 0 13 4
A GmpModifyPolicySetNvtSelectionTestMixin.test_modify_policy_set_nvt_selection_missing_family() 0 13 4
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2020-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
21
22
class GmpModifyPolicySetNvtSelectionTestMixin:
23
    def test_modify_policy_set_nvt_selection(self):
24
        self.gmp.modify_policy_set_nvt_selection(
25
            policy_id='c1', family='foo', nvt_oids=['o1']
26
        )
27
28
        self.connection.send.has_been_called_with(
29
            '<modify_config config_id="c1">'
30
            '<nvt_selection>'
31
            '<family>foo</family>'
32
            '<nvt oid="o1"/>'
33
            '</nvt_selection>'
34
            '</modify_config>'
35
        )
36
37
        self.gmp.modify_policy_set_nvt_selection(
38
            policy_id='c1', family='foo', nvt_oids=['o1', 'o2']
39
        )
40
41
        self.connection.send.has_been_called_with(
42
            '<modify_config config_id="c1">'
43
            '<nvt_selection>'
44
            '<family>foo</family>'
45
            '<nvt oid="o1"/>'
46
            '<nvt oid="o2"/>'
47
            '</nvt_selection>'
48
            '</modify_config>'
49
        )
50
51
        self.gmp.modify_policy_set_nvt_selection('c1', 'foo', ['o1'])
52
53
        self.connection.send.has_been_called_with(
54
            '<modify_config config_id="c1">'
55
            '<nvt_selection>'
56
            '<family>foo</family>'
57
            '<nvt oid="o1"/>'
58
            '</nvt_selection>'
59
            '</modify_config>'
60
        )
61
62
        self.gmp.modify_policy_set_nvt_selection('c1', 'foo', ('o1', 'o2'))
63
64
        self.connection.send.has_been_called_with(
65
            '<modify_config config_id="c1">'
66
            '<nvt_selection>'
67
            '<family>foo</family>'
68
            '<nvt oid="o1"/>'
69
            '<nvt oid="o2"/>'
70
            '</nvt_selection>'
71
            '</modify_config>'
72
        )
73
74
        self.gmp.modify_policy_set_nvt_selection(
75
            policy_id='c1', family='foo', nvt_oids=[]
76
        )
77
78
        self.connection.send.has_been_called_with(
79
            '<modify_config config_id="c1">'
80
            '<nvt_selection>'
81
            '<family>foo</family>'
82
            '</nvt_selection>'
83
            '</modify_config>'
84
        )
85
86
    def test_modify_policy_set_nvt_selection_missing_config_id(self):
87
        with self.assertRaises(RequiredArgument):
88
            self.gmp.modify_policy_set_nvt_selection(
89
                policy_id=None, family='foo', nvt_oids=['o1']
90
            )
91
92
        with self.assertRaises(RequiredArgument):
93
            self.gmp.modify_policy_set_nvt_selection(
94
                policy_id='', family='foo', nvt_oids=['o1']
95
            )
96
97
        with self.assertRaises(RequiredArgument):
98
            self.gmp.modify_policy_set_nvt_selection('', 'foo', ['o1'])
99
100
    def test_modify_policy_set_nvt_selection_missing_family(self):
101
        with self.assertRaises(RequiredArgument):
102
            self.gmp.modify_policy_set_nvt_selection(
103
                policy_id='c1', family=None, nvt_oids=['o1']
104
            )
105
106
        with self.assertRaises(RequiredArgument):
107
            self.gmp.modify_policy_set_nvt_selection(
108
                policy_id='c1', family='', nvt_oids=['o1']
109
            )
110
111
        with self.assertRaises(RequiredArgument):
112
            self.gmp.modify_policy_set_nvt_selection('c1', '', ['o1'])
113
114
    def test_modify_policy_set_nvt_selection_invalid_nvt_oids(self):
115
        with self.assertRaises(InvalidArgumentType):
116
            self.gmp.modify_policy_set_nvt_selection(
117
                policy_id='c1', family='foo', nvt_oids=None
118
            )
119
120
        with self.assertRaises(InvalidArgumentType):
121
            self.gmp.modify_policy_set_nvt_selection(
122
                policy_id='c1', family='foo', nvt_oids=''
123
            )
124
125
        with self.assertRaises(InvalidArgumentType):
126
            self.gmp.modify_policy_set_nvt_selection('c1', 'foo', '')
127