Passed
Pull Request — master (#244)
by
unknown
01:14
created

GmpModifyTicketTestCase.test_modify_ticket()   A

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nop 1
dl 11
loc 11
rs 10
c 0
b 0
f 0
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
import unittest
20
21
from gvm.errors import RequiredArgument, InvalidArgumentType
22
from gvm.protocols.gmpv9 import TicketStatus
23
24
from . import Gmpv9TestCase
25
26
27 View Code Duplication
class GmpModifyTicketTestCase(Gmpv9TestCase):
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
28
    def test_modify_ticket(self):
29
        self.gmp.modify_ticket('t1')
30
31
        self.connection.send.has_been_called_with(
32
            '<modify_ticket ticket_id="t1"/>'
33
        )
34
35
        self.gmp.modify_ticket(ticket_id='t1')
36
37
        self.connection.send.has_been_called_with(
38
            '<modify_ticket ticket_id="t1"/>'
39
        )
40
41
    def test_missing_ticket_id(self):
42
        with self.assertRaises(RequiredArgument):
43
            self.gmp.modify_ticket('')
44
45
        with self.assertRaises(RequiredArgument):
46
            self.gmp.modify_ticket(None)
47
48
        with self.assertRaises(RequiredArgument):
49
            self.gmp.modify_ticket(ticket_id=None)
50
51
    def test_modify_ticket_with_comment(self):
52
        self.gmp.modify_ticket(ticket_id='t1', comment='bar')
53
54
        self.connection.send.has_been_called_with(
55
            '<modify_ticket ticket_id="t1">'
56
            '<comment>bar</comment>'
57
            '</modify_ticket>'
58
        )
59
60
    def test_modify_ticket_with_assigned_to_user_id(self):
61
        self.gmp.modify_ticket(ticket_id='t1', assigned_to_user_id='u1')
62
63
        self.connection.send.has_been_called_with(
64
            '<modify_ticket ticket_id="t1">'
65
            '<assigned_to>'
66
            '<user id="u1"/>'
67
            '</assigned_to>'
68
            '</modify_ticket>'
69
        )
70
71
    def test_modify_ticket_invalid_status(self):
72
        with self.assertRaises(InvalidArgumentType):
73
            self.gmp.modify_ticket(ticket_id='t1', status='foobar', note='bar')
74
75
    def test_modify_ticket_open(self):
76
        self.gmp.modify_ticket(
77
            ticket_id='t1', status=TicketStatus.OPEN, note='lorem ipsum'
78
        )
79
80
        self.connection.send.has_been_called_with(
81
            '<modify_ticket ticket_id="t1">'
82
            '<status>Open</status>'
83
            '<open_note>lorem ipsum</open_note>'
84
            '</modify_ticket>'
85
        )
86
87
    def test_modify_ticket_fixed(self):
88
        self.gmp.modify_ticket(
89
            ticket_id='t1', status=TicketStatus.FIXED, note='lorem ipsum'
90
        )
91
92
        self.connection.send.has_been_called_with(
93
            '<modify_ticket ticket_id="t1">'
94
            '<status>Fixed</status>'
95
            '<fixed_note>lorem ipsum</fixed_note>'
96
            '</modify_ticket>'
97
        )
98
99
    def test_modify_ticket_closed(self):
100
        self.gmp.modify_ticket(
101
            ticket_id='t1', status=TicketStatus.CLOSED, note='lorem ipsum'
102
        )
103
104
        self.connection.send.has_been_called_with(
105
            '<modify_ticket ticket_id="t1">'
106
            '<status>Closed</status>'
107
            '<closed_note>lorem ipsum</closed_note>'
108
            '</modify_ticket>'
109
        )
110
111
    def test_modify_ticket_status_without_note(self):
112
        with self.assertRaises(RequiredArgument):
113
            self.gmp.modify_ticket(ticket_id='t1', status=TicketStatus.CLOSED)
114
115
    def test_modify_ticket_note_without_status(self):
116
        with self.assertRaises(RequiredArgument):
117
            self.gmp.modify_ticket(ticket_id='t1', note='foo')
118
119
120
if __name__ == '__main__':
121
    unittest.main()
122