Passed
Push — master ( 1e243f...b519bb )
by Björn
197:44 queued 153:47
created

tests.protocols.gmpv208.entities.scan_configs.test_import_scan_config   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpImportScanConfigTestMixin.test_import_scan_config() 0 7 1
A GmpImportScanConfigTestMixin.test_import_missing_scan_config_xml() 0 6 3
A GmpImportScanConfigTestMixin.test_import_invalid_xml() 0 3 2
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
from gvm.errors import RequiredArgument, InvalidArgument
20
21
22
class GmpImportScanConfigTestMixin:
23
24
    CONFIG_XML_STRING = (
25
        '<get_configs_response status="200" status_text="OK">'
26
        '<config id="c4aa21e4-23e6-4064-ae49-c0d425738a98">'
27
        '<name>Foobar</name>'
28
        '<comment>Foobar config</comment>'
29
        '<creation_time>2018-11-09T10:48:03Z</creation_time>'
30
        '<modification_time>2018-11-09T10:48:03Z</modification_time>'
31
        '</config>'
32
        '</get_configs_response>'
33
    )
34
35
    def test_import_scan_config(self):
36
        self.gmp.import_scan_config(self.CONFIG_XML_STRING)
37
38
        self.connection.send.has_been_called_with(
39
            '<create_config>'
40
            '{config}'
41
            '</create_config>'.format(config=self.CONFIG_XML_STRING)
42
        )
43
44
    def test_import_missing_scan_config_xml(self):
45
        with self.assertRaises(RequiredArgument):
46
            self.gmp.import_scan_config(None)
47
48
        with self.assertRaises(RequiredArgument):
49
            self.gmp.import_scan_config('')
50
51
    def test_import_invalid_xml(self):
52
        with self.assertRaises(InvalidArgument):
53
            self.gmp.import_scan_config('abcdef')
54