Passed
Pull Request — master (#54)
by
unknown
01:58
created

GmpCreateAgentTestCase.test_missing_signature()   A

Complexity

Conditions 3

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
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
class GmpCreateAgentTestCase(unittest.TestCase):
27
28
    def setUp(self):
29
        self.connection = MockConnection()
30
        self.gmp = Gmp(self.connection)
31
32
    def test_missing_installer(self):
33
        with self.assertRaises(RequiredArgument):
34
            self.gmp.create_agent(installer='', signature='foo', name='bar')
35
36
        with self.assertRaises(RequiredArgument):
37
            self.gmp.create_agent(installer=None, signature='foo', name='bar')
38
39
    def test_missing_signature(self):
40
        with self.assertRaises(RequiredArgument):
41
            self.gmp.create_agent(installer='foo', signature='', name='bar')
42
43
        with self.assertRaises(RequiredArgument):
44
            self.gmp.create_agent(installer='foo', signature=None, name='bar')
45
46
    def test_missing_name(self):
47
        with self.assertRaises(RequiredArgument):
48
            self.gmp.create_agent(installer='foo', signature='bar', name='')
49
50
        with self.assertRaises(RequiredArgument):
51
            self.gmp.create_agent(installer='foo', signature='bar', name=None)
52
53
    def test_create_agent(self):
54
        self.gmp.create_agent(installer='foo', signature='bar', name='ipsum')
55
56
        self.connection.send.has_been_called_with(
57
            '<create_agent>'
58
            '<installer>foo</installer>'
59
            '<signature>bar</signature>'
60
            '<name>ipsum</name>'
61
            '</create_agent>'
62
        )
63
64
    def test_create_agent_with_comment(self):
65
        self.gmp.create_agent(installer='foo', signature='bar', name='ipsum',
66
                              comment='lorem')
67
68
        self.connection.send.has_been_called_with(
69
            '<create_agent>'
70
            '<installer>foo</installer>'
71
            '<signature>bar</signature>'
72
            '<name>ipsum</name>'
73
            '<comment>lorem</comment>'
74
            '</create_agent>'
75
        )
76
77
    def test_create_agent_with_howto_install(self):
78
        self.gmp.create_agent(installer='foo', signature='bar', name='ipsum',
79
                              howto_install='lorem')
80
81
        self.connection.send.has_been_called_with(
82
            '<create_agent>'
83
            '<installer>foo</installer>'
84
            '<signature>bar</signature>'
85
            '<name>ipsum</name>'
86
            '<howto_install>lorem</howto_install>'
87
            '</create_agent>'
88
        )
89
90
    def test_create_agent_with_howto_use(self):
91
        self.gmp.create_agent(installer='foo', signature='bar', name='ipsum',
92
                              howto_use='lorem')
93
94
        self.connection.send.has_been_called_with(
95
            '<create_agent>'
96
            '<installer>foo</installer>'
97
            '<signature>bar</signature>'
98
            '<name>ipsum</name>'
99
            '<howto_use>lorem</howto_use>'
100
            '</create_agent>'
101
        )
102
103
104
if __name__ == '__main__':
105
    unittest.main()
106