Completed
Push — master ( af96e1...147191 )
by Jaspar
23s queued 16s
created

GmpModifyTicketTestMixin.test_modify_ticket_with_comment()   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) 2020-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, InvalidArgumentType
20
from gvm.protocols.gmpv208 import TicketStatus
21
22
23
class GmpModifyTicketTestMixin:
24
    def test_modify_ticket(self):
25
        self.gmp.modify_ticket('t1')
26
27
        self.connection.send.has_been_called_with(
28
            '<modify_ticket ticket_id="t1"/>'
29
        )
30
31
        self.gmp.modify_ticket(ticket_id='t1')
32
33
        self.connection.send.has_been_called_with(
34
            '<modify_ticket ticket_id="t1"/>'
35
        )
36
37
    def test_missing_ticket_id(self):
38
        with self.assertRaises(RequiredArgument):
39
            self.gmp.modify_ticket('')
40
41
        with self.assertRaises(RequiredArgument):
42
            self.gmp.modify_ticket(None)
43
44
        with self.assertRaises(RequiredArgument):
45
            self.gmp.modify_ticket(ticket_id=None)
46
47
    def test_modify_ticket_with_comment(self):
48
        self.gmp.modify_ticket(ticket_id='t1', comment='bar')
49
50
        self.connection.send.has_been_called_with(
51
            '<modify_ticket ticket_id="t1">'
52
            '<comment>bar</comment>'
53
            '</modify_ticket>'
54
        )
55
56
    def test_modify_ticket_with_assigned_to_user_id(self):
57
        self.gmp.modify_ticket(ticket_id='t1', assigned_to_user_id='u1')
58
59
        self.connection.send.has_been_called_with(
60
            '<modify_ticket ticket_id="t1">'
61
            '<assigned_to>'
62
            '<user id="u1"/>'
63
            '</assigned_to>'
64
            '</modify_ticket>'
65
        )
66
67
    def test_modify_ticket_invalid_status(self):
68
        with self.assertRaises(InvalidArgumentType):
69
            self.gmp.modify_ticket(ticket_id='t1', status='foobar', note='bar')
70
71
    def test_modify_ticket_open(self):
72
        self.gmp.modify_ticket(
73
            ticket_id='t1', status=TicketStatus.OPEN, note='lorem ipsum'
74
        )
75
76
        self.connection.send.has_been_called_with(
77
            '<modify_ticket ticket_id="t1">'
78
            '<status>Open</status>'
79
            '<open_note>lorem ipsum</open_note>'
80
            '</modify_ticket>'
81
        )
82
83
    def test_modify_ticket_fixed(self):
84
        self.gmp.modify_ticket(
85
            ticket_id='t1', status=TicketStatus.FIXED, note='lorem ipsum'
86
        )
87
88
        self.connection.send.has_been_called_with(
89
            '<modify_ticket ticket_id="t1">'
90
            '<status>Fixed</status>'
91
            '<fixed_note>lorem ipsum</fixed_note>'
92
            '</modify_ticket>'
93
        )
94
95
    def test_modify_ticket_closed(self):
96
        self.gmp.modify_ticket(
97
            ticket_id='t1', status=TicketStatus.CLOSED, note='lorem ipsum'
98
        )
99
100
        self.connection.send.has_been_called_with(
101
            '<modify_ticket ticket_id="t1">'
102
            '<status>Closed</status>'
103
            '<closed_note>lorem ipsum</closed_note>'
104
            '</modify_ticket>'
105
        )
106
107
    def test_modify_ticket_status_without_note(self):
108
        with self.assertRaises(RequiredArgument):
109
            self.gmp.modify_ticket(ticket_id='t1', status=TicketStatus.CLOSED)
110
111
    def test_modify_ticket_note_without_status(self):
112
        with self.assertRaises(RequiredArgument):
113
            self.gmp.modify_ticket(ticket_id='t1', note='foo')
114