Completed
Push — master ( de9ad4...519cea )
by Björn
25s queued 18s
created

tests.protocols.gmpv7.testcmds.test_import_report_format   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 62
rs 10
c 0
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A GmpImportReportFormatTestCase.test_import_missing_report_format_xml() 0 6 3
A GmpImportReportFormatTestCase.test_import_report_format() 0 8 1
A GmpImportReportFormatTestCase.test_import_invalid_xml() 0 3 2
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
23
24
class GmpImportReportFormatTestCase:
25
26
    REPORT_FORMAT_XML_STRING = (
27
        '<get_report_formats_response status="200" status_text="OK">'
28
        '<report_format id="c4aa21e4-23e6-4064-ae49-c0d425738a98">'
29
        '<name>Foobar</name>'
30
        '<comment>Foobar report_format</comment>'
31
        '<creation_time>2018-11-09T10:48:03Z</creation_time>'
32
        '<modification_time>2018-11-09T10:48:03Z</modification_time>'
33
        '</report_format>'
34
        '</get_report_formats_response>'
35
    )
36
37
    def test_import_report_format(self):
38
        self.gmp.import_report_format(self.REPORT_FORMAT_XML_STRING)
39
40
        self.connection.send.has_been_called_with(
41
            '<create_report_format>'
42
            '{report_format}'
43
            '</create_report_format>'.format(
44
                report_format=self.REPORT_FORMAT_XML_STRING
45
            )
46
        )
47
48
    def test_import_missing_report_format_xml(self):
49
        with self.assertRaises(RequiredArgument):
50
            self.gmp.import_report_format(None)
51
52
        with self.assertRaises(RequiredArgument):
53
            self.gmp.import_report_format('')
54
55
    def test_import_invalid_xml(self):
56
        with self.assertRaises(InvalidArgument):
57
            self.gmp.import_report_format('abcdef')
58
59
60
if __name__ == '__main__':
61
    unittest.main()
62