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

tests.protocols.gmpv7.test_get_assets   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 36
dl 0
loc 78
rs 10
c 0
b 0
f 0
wmc 8

5 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpGetAssetsTestCase.test_get_assets() 0 17 1
A GmpGetAssetsTestCase.setUp() 0 3 1
A GmpGetAssetsTestCase.test_get_assets_invalid_asset_type() 0 8 4
A GmpGetAssetsTestCase.test_get_assets_with_filter() 0 5 1
A GmpGetAssetsTestCase.test_get_assets_with_filter_id() 0 5 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 InvalidArgument
22
from gvm.protocols.gmpv7 import Gmp
23
24
from .. import MockConnection
25
26
27
class GmpGetAssetsTestCase(unittest.TestCase):
28
29
    def setUp(self):
30
        self.connection = MockConnection()
31
        self.gmp = Gmp(self.connection)
32
33
    def test_get_assets(self):
34
        self.gmp.get_assets('os')
35
36
        self.connection.send.has_been_called_with(
37
            '<get_assets type="os"/>'
38
        )
39
40
        self.gmp.get_assets(asset_type='os')
41
42
        self.connection.send.has_been_called_with(
43
            '<get_assets type="os"/>'
44
        )
45
46
        self.gmp.get_assets(asset_type='host')
47
48
        self.connection.send.has_been_called_with(
49
            '<get_assets type="host"/>'
50
        )
51
52
    def test_get_assets_invalid_asset_type(self):
53
        with self.assertRaises(InvalidArgument):
54
            self.gmp.get_assets(asset_type=None)
55
56
        with self.assertRaises(InvalidArgument):
57
            self.gmp.get_assets(asset_type='')
58
        with self.assertRaises(InvalidArgument):
59
            self.gmp.get_assets(asset_type='foo')
60
61
    def test_get_assets_with_filter(self):
62
        self.gmp.get_assets(asset_type='os', filter='foo=bar')
63
64
        self.connection.send.has_been_called_with(
65
            '<get_assets type="os" filter="foo=bar"/>'
66
        )
67
68
    def test_get_assets_with_filter_id(self):
69
        self.gmp.get_assets(asset_type='os', filter_id='f1')
70
71
        self.connection.send.has_been_called_with(
72
            '<get_assets type="os" filt_id="f1"/>'
73
        )
74
75
76
if __name__ == '__main__':
77
    unittest.main()
78