RequiredArgumentTestCase.test_is_ospd_error()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
# Copyright (C) 2014-2021 Greenbone Networks GmbH
2
#
3
# SPDX-License-Identifier: AGPL-3.0-or-later
4
#
5
# This program is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Affero General Public License as
7
# published by the Free Software Foundation, either version 3 of the
8
# License, or (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
# GNU Affero General Public License for more details.
14
#
15
# You should have received a copy of the GNU Affero General Public License
16
# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18
""" Test module for OspdCommandError class
19
"""
20
21
import unittest
22
23
from ospd.errors import OspdError, OspdCommandError, RequiredArgument
24
25
26
class OspdCommandErrorTestCase(unittest.TestCase):
27
    def test_is_ospd_error(self):
28
        e = OspdCommandError('message')
29
        self.assertIsInstance(e, OspdError)
30
31
    def test_default_params(self):
32
        e = OspdCommandError('message')
33
34
        self.assertEqual('message', e.message)
35
        self.assertEqual(400, e.status)
36
        self.assertEqual('osp', e.command)
37
38
    def test_constructor(self):
39
        e = OspdCommandError('message', 'command', 304)
40
41
        self.assertEqual('message', e.message)
42
        self.assertEqual('command', e.command)
43
        self.assertEqual(304, e.status)
44
45
    def test_string_conversion(self):
46
        e = OspdCommandError('message foo bar', 'command', 304)
47
48
        self.assertEqual('message foo bar', str(e))
49
50
    def test_as_xml(self):
51
        e = OspdCommandError('message')
52
53
        self.assertEqual(
54
            b'<osp_response status="400" status_text="message" />', e.as_xml()
55
        )
56
57
58
class RequiredArgumentTestCase(unittest.TestCase):
59
    def test_raise_exception(self):
60
        with self.assertRaises(RequiredArgument) as cm:
61
            raise RequiredArgument('foo', 'bar')
62
63
        ex = cm.exception
64
        self.assertEqual(ex.function, 'foo')
65
        self.assertEqual(ex.argument, 'bar')
66
67
    def test_string_conversion(self):
68
        ex = RequiredArgument('foo', 'bar')
69
        self.assertEqual(str(ex), 'foo: Argument bar is required')
70
71
    def test_is_ospd_error(self):
72
        e = RequiredArgument('foo', 'bar')
73
        self.assertIsInstance(e, OspdError)
74