Passed
Pull Request — master (#362)
by Jaspar
01:57 queued 13s
created

tests.protocols.gmpv208.testcmds.test_get_info_list   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 116
Duplicated Lines 73.28 %

Importance

Changes 0
Metric Value
eloc 56
dl 85
loc 116
rs 10
c 0
b 0
f 0
wmc 12

7 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpGetInfoListTestCase.test_get_info_list() 36 36 2
A GmpGetInfoListTestCase.test_get_info_list_with_details() 11 11 1
A GmpGetInfoListTestCase.test_get_info_list_with_filter_id() 5 5 1
A GmpGetInfoListTestCase.test_get_info_list_with_filter() 5 5 1
A GmpGetInfoListTestCase.test_get_info_list_missing_info_type() 9 9 4
A GmpGetInfoListTestCase.test_get_info_list_with_name() 5 5 1
A GmpGetInfoListTestCase.test_get_info_list_invalid_info_type() 3 3 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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, InvalidArgumentType
22
23
from gvm.protocols.gmpv208 import InfoType
24
25
26 View Code Duplication
class GmpGetInfoListTestCase:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
27
    def test_get_info_list(self):
28
        self.gmp.get_info_list(InfoType.CERT_BUND_ADV)
29
30
        self.connection.send.has_been_called_with(
31
            '<get_info type="CERT_BUND_ADV"/>'
32
        )
33
34
        self.gmp.get_info_list(InfoType.CPE)
35
36
        self.connection.send.has_been_called_with('<get_info type="CPE"/>')
37
38
        self.gmp.get_info_list(info_type=InfoType.CPE)
39
40
        self.connection.send.has_been_called_with('<get_info type="CPE"/>')
41
42
        self.gmp.get_info_list(InfoType.CVE)
43
44
        self.connection.send.has_been_called_with('<get_info type="CVE"/>')
45
46
        self.gmp.get_info_list(InfoType.DFN_CERT_ADV)
47
48
        self.connection.send.has_been_called_with(
49
            '<get_info type="DFN_CERT_ADV"/>'
50
        )
51
52
        self.gmp.get_info_list(InfoType.OVALDEF)
53
54
        self.connection.send.has_been_called_with('<get_info type="OVALDEF"/>')
55
56
        self.gmp.get_info_list(InfoType.NVT)
57
58
        self.connection.send.has_been_called_with('<get_info type="NVT"/>')
59
60
        with self.assertRaises(AttributeError):
61
            self.gmp.get_info_list(
62
                InfoType.ALLINFO  # pylint: disable=no-member
63
            )
64
65
    def test_get_info_list_missing_info_type(self):
66
        with self.assertRaises(RequiredArgument):
67
            self.gmp.get_info_list(info_type=None)
68
69
        with self.assertRaises(RequiredArgument):
70
            self.gmp.get_info_list(info_type='')
71
72
        with self.assertRaises(RequiredArgument):
73
            self.gmp.get_info_list('')
74
75
    def test_get_info_list_invalid_info_type(self):
76
        with self.assertRaises(InvalidArgumentType):
77
            self.gmp.get_info_list(info_type='foo')
78
79
    def test_get_info_list_with_filter(self):
80
        self.gmp.get_info_list(InfoType.CPE, filter='foo=bar')
81
82
        self.connection.send.has_been_called_with(
83
            '<get_info type="CPE" filter="foo=bar"/>'
84
        )
85
86
    def test_get_info_list_with_filter_id(self):
87
        self.gmp.get_info_list(info_type=InfoType.CPE, filter_id='f1')
88
89
        self.connection.send.has_been_called_with(
90
            '<get_info type="CPE" filt_id="f1"/>'
91
        )
92
93
    def test_get_info_list_with_name(self):
94
        self.gmp.get_info_list(info_type=InfoType.CPE, name='foo')
95
96
        self.connection.send.has_been_called_with(
97
            '<get_info type="CPE" name="foo"/>'
98
        )
99
100
    def test_get_info_list_with_details(self):
101
        self.gmp.get_info_list(info_type=InfoType.CPE, details=True)
102
103
        self.connection.send.has_been_called_with(
104
            '<get_info type="CPE" details="1"/>'
105
        )
106
107
        self.gmp.get_info_list(info_type=InfoType.CPE, details=False)
108
109
        self.connection.send.has_been_called_with(
110
            '<get_info type="CPE" details="0"/>'
111
        )
112
113
114
if __name__ == '__main__':
115
    unittest.main()
116