Passed
Pull Request — master (#107)
by Michael
01:59
created

tests.protocols.gmpv7.test_get_aggregates   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 151
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 73
dl 0
loc 151
rs 10
c 0
b 0
f 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpGetAggregatesTestCase.test_get_aggregates_kwargs() 0 5 1
A GmpGetAggregatesTestCase.test_get_aggregates_invalid_resource_type() 0 3 2
A GmpGetAggregatesTestCase.test_get_aggregates_missing_resource_type() 0 9 4
B GmpGetAggregatesTestCase.test_get_aggregates() 0 93 1
A GmpGetAggregatesTestCase.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, InvalidArgument
22
from gvm.protocols.gmpv7 import Gmp
23
24
from .. import MockConnection
25
26
27
class GmpGetAggregatesTestCase(unittest.TestCase):
28
    def setUp(self):
29
        self.connection = MockConnection()
30
        self.gmp = Gmp(self.connection)
31
32
    def test_get_aggregates(self):
33
        self.gmp.get_aggregates('alert')
34
35
        self.connection.send.has_been_called_with(
36
            '<get_aggregates type="alert"/>'
37
        )
38
39
        self.gmp.get_aggregates('allinfo')
40
41
        self.connection.send.has_been_called_with(
42
            '<get_aggregates type="allinfo"/>'
43
        )
44
45
        self.gmp.get_aggregates(resource_type='cert_bund_adv')
46
47
        self.connection.send.has_been_called_with(
48
            '<get_aggregates type="cert_bund_adv"/>'
49
        )
50
51
        self.gmp.get_aggregates('cpe')
52
53
        self.connection.send.has_been_called_with(
54
            '<get_aggregates type="cpe"/>'
55
        )
56
57
        self.gmp.get_aggregates('cve')
58
59
        self.connection.send.has_been_called_with(
60
            '<get_aggregates type="cve"/>'
61
        )
62
63
        self.gmp.get_aggregates('dfn_cert_adv')
64
65
        self.connection.send.has_been_called_with(
66
            '<get_aggregates type="dfn_cert_adv"/>'
67
        )
68
69
        self.gmp.get_aggregates('host')
70
71
        self.connection.send.has_been_called_with(
72
            '<get_aggregates type="host"/>'
73
        )
74
75
        self.gmp.get_aggregates('note')
76
77
        self.connection.send.has_been_called_with(
78
            '<get_aggregates type="note"/>'
79
        )
80
81
        self.gmp.get_aggregates('nvt')
82
83
        self.connection.send.has_been_called_with(
84
            '<get_aggregates type="nvt"/>'
85
        )
86
87
        self.gmp.get_aggregates('os')
88
89
        self.connection.send.has_been_called_with('<get_aggregates type="os"/>')
90
91
        self.gmp.get_aggregates('ovaldef')
92
93
        self.connection.send.has_been_called_with(
94
            '<get_aggregates type="ovaldef"/>'
95
        )
96
97
        self.gmp.get_aggregates('override')
98
99
        self.connection.send.has_been_called_with(
100
            '<get_aggregates type="override"/>'
101
        )
102
103
        self.gmp.get_aggregates('report')
104
105
        self.connection.send.has_been_called_with(
106
            '<get_aggregates type="report"/>'
107
        )
108
109
        self.gmp.get_aggregates('result')
110
111
        self.connection.send.has_been_called_with(
112
            '<get_aggregates type="result"/>'
113
        )
114
115
        self.gmp.get_aggregates('task')
116
117
        self.connection.send.has_been_called_with(
118
            '<get_aggregates type="task"/>'
119
        )
120
121
        self.gmp.get_aggregates('vuln')
122
123
        self.connection.send.has_been_called_with(
124
            '<get_aggregates type="vuln"/>'
125
        )
126
127
    def test_get_aggregates_kwargs(self):
128
        self.gmp.get_aggregates('alert', group_column="family")
129
130
        self.connection.send.has_been_called_with(
131
            '<get_aggregates type="alert" group_column="family"/>'
132
        )
133
134
    def test_get_aggregates_missing_resource_type(self):
135
        with self.assertRaises(RequiredArgument):
136
            self.gmp.get_aggregates(resource_type=None)
137
138
        with self.assertRaises(RequiredArgument):
139
            self.gmp.get_aggregates(resource_type='')
140
141
        with self.assertRaises(RequiredArgument):
142
            self.gmp.get_aggregates('')
143
144
    def test_get_aggregates_invalid_resource_type(self):
145
        with self.assertRaises(InvalidArgument):
146
            self.gmp.get_aggregates(resource_type='foo')
147
148
149
if __name__ == '__main__':
150
    unittest.main()
151