Passed
Pull Request — master (#469)
by Jaspar
92:15 queued 90:46
created

GmpCreateScheduleTestMixin.test_missing_timezone()   A

Complexity

Conditions 3

Size

Total Lines 12
Code Lines 9

Duplication

Lines 12
Ratio 100 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nop 1
dl 12
loc 12
rs 9.95
c 0
b 0
f 0
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2019-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
20
21
22
ICAL = """
23
BEGIN:VCALENDAR
24
VERSION:2.0
25
PRODID:-//Greenbone.net//NONSGML Greenbone Security Manager 8.0.0//EN
26
BEGIN:VEVENT
27
UID:c35f82f1-7798-4b84-b2c4-761a33068956
28
DTSTAMP:20190715T124352Z
29
DTSTART:20190716T040000Z
30
END:VEVENT
31
END:VCALENDAR
32
"""
33
34
35
class GmpCreateScheduleTestMixin:
36 View Code Duplication
    def test_missing_name(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
37
        with self.assertRaises(RequiredArgument) as cm:
38
            self.gmp.create_schedule(name=None, icalendar=ICAL, timezone='UTC')
39
40
        ex = cm.exception
41
        self.assertEqual(ex.argument, "name")
42
43
        with self.assertRaises(RequiredArgument) as cm:
44
            self.gmp.create_schedule(name='', icalendar=ICAL, timezone='UTC')
45
46
        ex = cm.exception
47
        self.assertEqual(ex.argument, "name")
48
49 View Code Duplication
    def test_missing_icalendar(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
50
        with self.assertRaises(RequiredArgument) as cm:
51
            self.gmp.create_schedule(name='foo', icalendar=None, timezone='UTC')
52
53
        ex = cm.exception
54
        self.assertEqual(ex.argument, "icalendar")
55
56
        with self.assertRaises(RequiredArgument) as cm:
57
            self.gmp.create_schedule(name='foo', icalendar='', timezone='UTC')
58
59
        ex = cm.exception
60
        self.assertEqual(ex.argument, "icalendar")
61
62 View Code Duplication
    def test_missing_timezone(self):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
63
        with self.assertRaises(RequiredArgument) as cm:
64
            self.gmp.create_schedule(name='foo', icalendar=ICAL, timezone=None)
65
66
        ex = cm.exception
67
        self.assertEqual(ex.argument, "timezone")
68
69
        with self.assertRaises(RequiredArgument) as cm:
70
            self.gmp.create_schedule(name='foo', icalendar=ICAL, timezone='')
71
72
        ex = cm.exception
73
        self.assertEqual(ex.argument, "timezone")
74
75
    def test_create_schedule(self):
76
        self.gmp.create_schedule(
77
            name='foo', icalendar=ICAL, timezone='Europe/Berlin'
78
        )
79
80
        self.connection.send.has_been_called_with(
81
            "<create_schedule>"
82
            "<name>foo</name>"
83
            "<icalendar>{}</icalendar>"
84
            "<timezone>Europe/Berlin</timezone>"
85
            "</create_schedule>".format(ICAL)
86
        )
87
88
    def test_create_schedule_with_comment(self):
89
        self.gmp.create_schedule(
90
            name='foo', icalendar=ICAL, timezone='Europe/Berlin', comment="bar"
91
        )
92
93
        self.connection.send.has_been_called_with(
94
            "<create_schedule>"
95
            "<name>foo</name>"
96
            "<icalendar>{}</icalendar>"
97
            "<timezone>Europe/Berlin</timezone>"
98
            "<comment>bar</comment>"
99
            "</create_schedule>".format(ICAL)
100
        )
101