File: test_create_schedule.py

package info (click to toggle)
python-gvm 26.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 5,132 kB
  • sloc: python: 44,662; makefile: 18
file content (86 lines) | stat: -rw-r--r-- 2,691 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# SPDX-FileCopyrightText: 2019-2024 Greenbone AG
#
# SPDX-License-Identifier: GPL-3.0-or-later
#

from gvm.errors import RequiredArgument

ICAL = """
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Greenbone.net//NONSGML Greenbone Security Manager 8.0.0//EN
BEGIN:VEVENT
UID:c35f82f1-7798-4b84-b2c4-761a33068956
DTSTAMP:20190715T124352Z
DTSTART:20190716T040000Z
END:VEVENT
END:VCALENDAR
"""


class GmpCreateScheduleTestMixin:
    def test_missing_name(self):
        with self.assertRaises(RequiredArgument) as cm:
            self.gmp.create_schedule(name=None, icalendar=ICAL, timezone="UTC")

        ex = cm.exception
        self.assertEqual(ex.argument, "name")

        with self.assertRaises(RequiredArgument) as cm:
            self.gmp.create_schedule(name="", icalendar=ICAL, timezone="UTC")

        ex = cm.exception
        self.assertEqual(ex.argument, "name")

    def test_missing_icalendar(self):
        with self.assertRaises(RequiredArgument) as cm:
            self.gmp.create_schedule(name="foo", icalendar=None, timezone="UTC")

        ex = cm.exception
        self.assertEqual(ex.argument, "icalendar")

        with self.assertRaises(RequiredArgument) as cm:
            self.gmp.create_schedule(name="foo", icalendar="", timezone="UTC")

        ex = cm.exception
        self.assertEqual(ex.argument, "icalendar")

    def test_missing_timezone(self):
        with self.assertRaises(RequiredArgument) as cm:
            self.gmp.create_schedule(name="foo", icalendar=ICAL, timezone=None)

        ex = cm.exception
        self.assertEqual(ex.argument, "timezone")

        with self.assertRaises(RequiredArgument) as cm:
            self.gmp.create_schedule(name="foo", icalendar=ICAL, timezone="")

        ex = cm.exception
        self.assertEqual(ex.argument, "timezone")

    def test_create_schedule(self):
        self.gmp.create_schedule(
            name="foo", icalendar=ICAL, timezone="Europe/Berlin"
        )

        self.connection.send.has_been_called_with(
            "<create_schedule>"
            "<name>foo</name>"
            f"<icalendar>{ICAL}</icalendar>"
            "<timezone>Europe/Berlin</timezone>"
            "</create_schedule>".encode("utf-8")
        )

    def test_create_schedule_with_comment(self):
        self.gmp.create_schedule(
            name="foo", icalendar=ICAL, timezone="Europe/Berlin", comment="bar"
        )

        self.connection.send.has_been_called_with(
            "<create_schedule>"
            "<name>foo</name>"
            f"<icalendar>{ICAL}</icalendar>"
            "<timezone>Europe/Berlin</timezone>"
            "<comment>bar</comment>"
            "</create_schedule>".encode("utf-8")
        )