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): |
|
|
|
|
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): |
|
|
|
|
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): |
|
|
|
|
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
|
|
|
|