tests.command.test_registry   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 39
dl 0
loc 76
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A RegistryTestCase.test_available_commands() 0 8 1
A RegistryTestCase.test_register_command() 0 29 1
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
from unittest import TestCase
19
20
from ospd.command.registry import get_commands, register_command, remove_command
21
22
23
COMMAND_NAMES = [
24
    "help",
25
    "get_version",
26
    "get_performance",
27
    "get_scanner_details",
28
    "delete_scan",
29
    "get_vts",
30
    "stop_scan",
31
    "get_scans",
32
    "start_scan",
33
    "get_memory_usage",
34
]
35
36
37
class RegistryTestCase(TestCase):
38
    def test_available_commands(self):
39
        commands = get_commands()
40
41
        self.assertEqual(len(COMMAND_NAMES), len(commands))
42
43
        c_list = [c.name for c in commands]
44
45
        self.assertListEqual(COMMAND_NAMES, c_list)
46
47
    def test_register_command(self):
48
        commands = get_commands()
49
        before = len(commands)
50
51
        class Foo:
52
            name = 'foo'
53
54
        register_command(Foo)
55
56
        commands = get_commands()
57
        after = len(commands)
58
59
        try:
60
            self.assertEqual(before + 1, after)
61
62
            c_dict = {c.name: c for c in commands}
63
64
            self.assertIn('foo', c_dict)
65
            self.assertIs(c_dict['foo'], Foo)
66
        finally:
67
            remove_command(Foo)
68
69
        commands = get_commands()
70
        after2 = len(commands)
71
72
        self.assertEqual(before, after2)
73
74
        c_dict = {c.name: c for c in commands}
75
        self.assertNotIn('foo', c_dict)
76