Completed
Push — master ( d15ae4...af96e1 )
by Björn
31s queued 22s
created

GmpModifyScheduleTestMixin.test_modify_schedule_with_name()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nop 1
dl 0
loc 5
rs 10
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 GmpModifyScheduleTestMixin:
36
    def test_missing_schedule_id(self):
37
        with self.assertRaises(RequiredArgument) as cm:
38
            self.gmp.modify_schedule(schedule_id=None)
39
40
        ex = cm.exception
41
        self.assertEqual(ex.argument, "schedule_id")
42
43
        with self.assertRaises(RequiredArgument) as cm:
44
            self.gmp.modify_schedule(schedule_id='')
45
46
        ex = cm.exception
47
        self.assertEqual(ex.argument, "schedule_id")
48
49
    def test_modify_schedule_with_name(self):
50
        self.gmp.modify_schedule(schedule_id='s1', name='foo')
51
52
        self.connection.send.has_been_called_with(
53
            '<modify_schedule schedule_id="s1">'
54
            "<name>foo</name>"
55
            "</modify_schedule>"
56
        )
57
58
    def test_modify_schedule_with_comment(self):
59
        self.gmp.modify_schedule(schedule_id="s1", comment="bar")
60
61
        self.connection.send.has_been_called_with(
62
            '<modify_schedule schedule_id="s1">'
63
            "<comment>bar</comment>"
64
            "</modify_schedule>"
65
        )
66
67
    def test_modify_schedule_with_icalendar(self):
68
        self.gmp.modify_schedule(schedule_id="s1", icalendar=ICAL)
69
70
        self.connection.send.has_been_called_with(
71
            '<modify_schedule schedule_id="s1">'
72
            '<icalendar>{}</icalendar>'
73
            "</modify_schedule>".format(ICAL)
74
        )
75
76
    def test_modify_schedule_with_timezone(self):
77
        self.gmp.modify_schedule(schedule_id="s1", timezone="Europe/Berlin")
78
79
        self.connection.send.has_been_called_with(
80
            '<modify_schedule schedule_id="s1">'
81
            '<timezone>Europe/Berlin</timezone>'
82
            "</modify_schedule>"
83
        )
84