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

tests.protocols.gmpv208.entities.policies.test_modify_policy_set_nvt_preference   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 45
dl 0
loc 107
rs 10
c 0
b 0
f 0
wmc 14

5 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpModifyPolicySetNvtPreferenceTestMixin.test_modify_policy_nvt_pref_missing_name() 0 14 4
A GmpModifyPolicySetNvtPreferenceTestMixin.test_modify_policy_set_nvt_pref_missing_nvt_oid() 0 14 4
A GmpModifyPolicySetNvtPreferenceTestMixin.test_modify_policy_set_comment_missing_config_id() 0 12 4
A GmpModifyPolicySetNvtPreferenceTestMixin.test_modify_policy_set_nvt_pref() 0 18 1
A GmpModifyPolicySetNvtPreferenceTestMixin.test_modify_policy_set_nvt_pref_with_value() 0 7 1
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
20
21
22
class GmpModifyPolicySetNvtPreferenceTestMixin:
23
    def test_modify_policy_set_nvt_pref(self):
24
        self.gmp.modify_policy_set_nvt_preference(
25
            policy_id='c1', nvt_oid='o1', name='foo'
26
        )
27
28
        self.connection.send.has_been_called_with(
29
            '<modify_config config_id="c1">'
30
            '<preference>'
31
            '<nvt oid="o1"/>'
32
            '<name>foo</name>'
33
            '</preference>'
34
            '</modify_config>'
35
        )
36
37
        self.gmp.modify_policy_set_nvt_preference('c1', 'foo', 'o1')
38
39
        self.connection.send.has_been_called_with(
40
            '<modify_config config_id="c1">'
41
            '<preference>'
42
            '<nvt oid="o1"/>'
43
            '<name>foo</name>'
44
            '</preference>'
45
            '</modify_config>'
46
        )
47
48
    def test_modify_policy_set_nvt_pref_with_value(self):
49
        self.gmp.modify_policy_set_nvt_preference(
50
            'c1', 'foo', nvt_oid='o1', value='bar'
51
        )
52
53
        self.connection.send.has_been_called_with(
54
            '<modify_config config_id="c1">'
55
            '<preference>'
56
            '<nvt oid="o1"/>'
57
            '<name>foo</name>'
58
            '<value>YmFy</value>'
59
            '</preference>'
60
            '</modify_config>'
61
        )
62
63
    def test_modify_policy_set_nvt_pref_missing_nvt_oid(self):
64
        with self.assertRaises(RequiredArgument):
65
            self.gmp.modify_policy_set_nvt_preference(
66
                'c1', 'foo', nvt_oid=None, value='bar'
67
            )
68
69
        with self.assertRaises(RequiredArgument):
70
            self.gmp.modify_policy_set_nvt_preference(
71
                'c1', 'foo', nvt_oid='', value='bar'
72
            )
73
74
        with self.assertRaises(RequiredArgument):
75
            self.gmp.modify_policy_set_nvt_preference(
76
                'c1', 'foo', '', value='bar'
77
            )
78
79
    def test_modify_policy_nvt_pref_missing_name(self):
80
        with self.assertRaises(RequiredArgument):
81
            self.gmp.modify_policy_set_nvt_preference(
82
                'c1', name=None, nvt_oid='o1', value='bar'
83
            )
84
85
        with self.assertRaises(RequiredArgument):
86
            self.gmp.modify_policy_set_nvt_preference(
87
                'c1', name='', nvt_oid='o1', value='bar'
88
            )
89
90
        with self.assertRaises(RequiredArgument):
91
            self.gmp.modify_policy_set_nvt_preference(
92
                'c1', '', nvt_oid='o1', value='bar'
93
            )
94
95
    def test_modify_policy_set_comment_missing_config_id(self):
96
        with self.assertRaises(RequiredArgument):
97
            self.gmp.modify_policy_set_nvt_preference(
98
                policy_id=None, name='foo', nvt_oid='o1'
99
            )
100
101
        with self.assertRaises(RequiredArgument):
102
            self.gmp.modify_policy_set_nvt_preference('', 'foo', 'o1')
103
104
        with self.assertRaises(RequiredArgument):
105
            self.gmp.modify_policy_set_nvt_preference(
106
                policy_id='', name='foo', nvt_oid='o1'
107
            )
108