Completed
Push — master ( 48663a...f3cde9 )
by
unknown
31s queued 11s
created

tests.protocols.gmpv7.test_get_info   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 50
dl 0
loc 103
rs 10
c 0
b 0
f 0
wmc 12

5 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpGetInfoTestCase.test_get_info_missing_info_id() 0 9 4
A GmpGetInfoTestCase.test_get_info() 0 41 1
A GmpGetInfoTestCase.setUp() 0 3 1
A GmpGetInfoTestCase.test_get_info_invalid_info_type() 0 3 2
A GmpGetInfoTestCase.test_get_info_missing_info_type() 0 9 4
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 GmpGetInfoTestCase(unittest.TestCase):
28
29
    def setUp(self):
30
        self.connection = MockConnection()
31
        self.gmp = Gmp(self.connection)
32
33
    def test_get_info(self):
34
        self.gmp.get_info(info_type='cert_bund_adv', info_id='i1')
35
36
        self.connection.send.has_been_called_with(
37
            '<get_info info_id="i1" type="CERT_BUND_ADV" details="1"/>'
38
        )
39
40
        self.gmp.get_info('i1', 'cpe')
41
42
        self.connection.send.has_been_called_with(
43
            '<get_info info_id="i1" type="CPE" details="1"/>'
44
        )
45
46
        self.gmp.get_info('i1', 'cve')
47
48
        self.connection.send.has_been_called_with(
49
            '<get_info info_id="i1" type="CVE" details="1"/>'
50
        )
51
52
        self.gmp.get_info('i1', 'dfn_cert_adv')
53
54
        self.connection.send.has_been_called_with(
55
            '<get_info info_id="i1" type="DFN_CERT_ADV" details="1"/>'
56
        )
57
58
        self.gmp.get_info('i1', 'ovaldef')
59
60
        self.connection.send.has_been_called_with(
61
            '<get_info info_id="i1" type="OVALDEF" details="1"/>'
62
        )
63
64
        self.gmp.get_info('i1', 'nvt')
65
66
        self.connection.send.has_been_called_with(
67
            '<get_info info_id="i1" type="NVT" details="1"/>'
68
        )
69
70
        self.gmp.get_info('i1', 'allinfo')
71
72
        self.connection.send.has_been_called_with(
73
            '<get_info info_id="i1" type="ALLINFO" details="1"/>'
74
        )
75
76
    def test_get_info_missing_info_type(self):
77
        with self.assertRaises(RequiredArgument):
78
            self.gmp.get_info(info_id='i1', info_type=None)
79
80
        with self.assertRaises(RequiredArgument):
81
            self.gmp.get_info(info_id='i1', info_type='')
82
83
        with self.assertRaises(RequiredArgument):
84
            self.gmp.get_info('i1', '')
85
86
    def test_get_info_invalid_info_type(self):
87
        with self.assertRaises(InvalidArgument):
88
            self.gmp.get_info(info_id='i1', info_type='foo')
89
90
    def test_get_info_missing_info_id(self):
91
        with self.assertRaises(RequiredArgument):
92
            self.gmp.get_info(info_id='', info_type='cpe')
93
94
        with self.assertRaises(RequiredArgument):
95
            self.gmp.get_info('', info_type='cpe')
96
97
        with self.assertRaises(RequiredArgument):
98
            self.gmp.get_info(info_id=None, info_type='cpe')
99
100
101
if __name__ == '__main__':
102
    unittest.main()
103