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

tests.protocols.gmpv7.test_modify_setting   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 46
dl 0
loc 100
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpModifySettingTestCase.test_modify_setting_missing_name() 0 9 3
A GmpModifySettingTestCase.setUp() 0 3 1
A GmpModifySettingTestCase.test_modify_setting_missing_setting_id() 0 9 3
A GmpModifySettingTestCase.test_modify_setting() 0 31 1
A GmpModifySettingTestCase.test_modify_setting_missing_value() 0 5 2
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 GmpModifySettingTestCase(unittest.TestCase):
28
29
    def setUp(self):
30
        self.connection = MockConnection()
31
        self.gmp = Gmp(self.connection)
32
33
    def test_modify_setting(self):
34
        self.gmp.modify_setting(
35
            setting_id='s1',
36
            value='bar',
37
        )
38
39
        self.connection.send.has_been_called_with(
40
            '<modify_setting setting_id="s1">'
41
            '<value>bar</value>'
42
            '</modify_setting>'
43
        )
44
45
        self.gmp.modify_setting(
46
            name='s1',
47
            value='bar',
48
        )
49
50
        self.connection.send.has_been_called_with(
51
            '<modify_setting>'
52
            '<name>s1</name>'
53
            '<value>bar</value>'
54
            '</modify_setting>'
55
        )
56
57
        self.gmp.modify_setting(
58
            setting_id='s1',
59
            value='',
60
        )
61
62
        self.connection.send.has_been_called_with(
63
            '<modify_setting setting_id="s1">'
64
            '<value></value>'
65
            '</modify_setting>'
66
        )
67
68
    def test_modify_setting_missing_setting_id(self):
69
        with self.assertRaises(RequiredArgument):
70
            self.gmp.modify_setting(
71
                setting_id=None,
72
            )
73
74
        with self.assertRaises(RequiredArgument):
75
            self.gmp.modify_setting(
76
                setting_id='',
77
            )
78
79
    def test_modify_setting_missing_name(self):
80
        with self.assertRaises(RequiredArgument):
81
            self.gmp.modify_setting(
82
                name=None,
83
            )
84
85
        with self.assertRaises(RequiredArgument):
86
            self.gmp.modify_setting(
87
                name='',
88
            )
89
90
    def test_modify_setting_missing_value(self):
91
        with self.assertRaises(RequiredArgument):
92
            self.gmp.modify_setting(
93
                setting_id='s1',
94
                value=None,
95
            )
96
97
98
if __name__ == '__main__':
99
    unittest.main()
100