1
|
|
|
# -*- coding: utf-8 -*- |
2
|
|
|
# Copyright (C) 2020 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
|
|
|
|
20
|
|
|
import unittest |
21
|
|
|
from unittest.mock import patch |
22
|
|
|
from pathlib import Path |
23
|
|
|
from argparse import Namespace |
24
|
|
|
from lxml import etree |
25
|
|
|
from . import GmpMockFactory, load_script |
26
|
|
|
|
27
|
|
|
CWD = Path(__file__).absolute().parent |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class SendSchedulesTestCase(unittest.TestCase): |
31
|
|
|
def setUp(self): |
32
|
|
|
self.send_schedules = load_script( |
33
|
|
|
(CWD.parent.parent / 'scripts'), 'send-schedules' |
34
|
|
|
) |
35
|
|
|
|
36
|
|
|
@patch('gvm.protocols.latest.Gmp', new_callable=GmpMockFactory) |
37
|
|
|
def test_sent_schedule(self, mock_gmp: GmpMockFactory): |
38
|
|
|
schedule_xml_path = CWD / 'example_schedules.xml' |
39
|
|
|
schedule_xml_str = schedule_xml_path.read_text() |
40
|
|
|
|
41
|
|
|
mock_gmp.mock_responses( |
42
|
|
|
'create_schedule', |
43
|
|
|
[ |
44
|
|
|
'<create_schedule_response status="201" status_text="OK,' |
45
|
|
|
'resource created" id="75be149a-0877-40f9-97c0-dfea31311e35"/>', |
46
|
|
|
'<create_schedule_response status="201" status_text="OK,' |
47
|
|
|
'resource created" id="42da6616-f32d-47b4-8d6b-2e4553c42ee7"/>', |
48
|
|
|
], |
49
|
|
|
) |
50
|
|
|
|
51
|
|
|
schedule = etree.XML(schedule_xml_str) |
52
|
|
|
|
53
|
|
|
self.send_schedules.parse_send_xml_tree(mock_gmp.gmp_protocol, schedule) |
54
|
|
|
|
55
|
|
|
def test_args(self): |
56
|
|
|
args = Namespace(script=['foo']) |
57
|
|
|
with self.assertRaises(SystemExit): |
58
|
|
|
self.send_schedules.check_args(args) |
59
|
|
|
|
60
|
|
|
args2 = Namespace(script=['foo', 'bar', 'baz']) |
61
|
|
|
|
62
|
|
|
with self.assertRaises(SystemExit): |
63
|
|
|
self.send_schedules.check_args(args2) |
64
|
|
|
|