Completed
Push — master ( 0d5311...c5499f )
by Jaspar
22s queued 17s
created

tests.protocols.gmpv208.testcmds.test_get_assets   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 56.34 %

Importance

Changes 0
Metric Value
eloc 31
dl 40
loc 71
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpGetAssetsTestCase.test_get_assets_invalid_asset_type() 9 9 4
A GmpGetAssetsTestCase.test_get_assets() 12 12 1
A GmpGetAssetsTestCase.test_get_assets_with_filter() 7 7 1
A GmpGetAssetsTestCase.test_get_assets_with_filter_id() 7 7 1

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-2021 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 InvalidArgumentType
22
23
from gvm.protocols.gmpv208 import AssetType
24
25
26 View Code Duplication
class GmpGetAssetsTestCase:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
27
    def test_get_assets(self):
28
        self.gmp.get_assets(AssetType.OPERATING_SYSTEM)
29
30
        self.connection.send.has_been_called_with('<get_assets type="os"/>')
31
32
        self.gmp.get_assets(asset_type=AssetType.OPERATING_SYSTEM)
33
34
        self.connection.send.has_been_called_with('<get_assets type="os"/>')
35
36
        self.gmp.get_assets(asset_type=AssetType.HOST)
37
38
        self.connection.send.has_been_called_with('<get_assets type="host"/>')
39
40
    def test_get_assets_invalid_asset_type(self):
41
        with self.assertRaises(InvalidArgumentType):
42
            self.gmp.get_assets(asset_type=None)
43
44
        with self.assertRaises(InvalidArgumentType):
45
            self.gmp.get_assets(asset_type='')
46
47
        with self.assertRaises(InvalidArgumentType):
48
            self.gmp.get_assets(asset_type='foo')
49
50
    def test_get_assets_with_filter(self):
51
        self.gmp.get_assets(
52
            asset_type=AssetType.OPERATING_SYSTEM, filter='foo=bar'
53
        )
54
55
        self.connection.send.has_been_called_with(
56
            '<get_assets type="os" filter="foo=bar"/>'
57
        )
58
59
    def test_get_assets_with_filter_id(self):
60
        self.gmp.get_assets(
61
            asset_type=AssetType.OPERATING_SYSTEM, filter_id='f1'
62
        )
63
64
        self.connection.send.has_been_called_with(
65
            '<get_assets type="os" filt_id="f1"/>'
66
        )
67
68
69
if __name__ == '__main__':
70
    unittest.main()
71