Completed
Push — master ( 3b0190...8082e9 )
by Juan José
13s queued 11s
created

tests.testTargetConvert   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 50
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testTargetLists.test24Net() 0 6 2
A testTargetLists.testRange() 0 6 2
A testTargetLists.testGetHostnameByAddress() 0 7 1
1
# Copyright (C) 2014-2018 Greenbone Networks GmbH
2
#
3
# SPDX-License-Identifier: GPL-2.0-or-later
4
#
5
# This program is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU General Public License
7
# as published by the Free Software Foundation; either version 2
8
# of the 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 General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
19
""" Test suites for Target manipulations.
20
"""
21
22
import unittest
23
24
from ospd.misc import target_str_to_list
25
from ospd.misc import get_hostname_by_address
26
27
class testTargetLists(unittest.TestCase):
28
29
    def test24Net(self):
30
        addresses = target_str_to_list('195.70.81.0/24')
31
        self.assertFalse(addresses is None)
32
        self.assertEqual(len(addresses), 254)
33
        for i in range(1, 255):
34
            self.assertTrue('195.70.81.%d' % i in addresses)
35
36
    def testRange(self):
37
        addresses = target_str_to_list('195.70.81.1-10')
38
        self.assertFalse(addresses is None)
39
        self.assertEqual(len(addresses), 10)
40
        for i in range(1, 10):
41
            self.assertTrue('195.70.81.%d' % i in addresses)
42
43
    def testGetHostnameByAddress(self):
44
        hostname = get_hostname_by_address('127.0.0.1')
45
        self.assertEqual(hostname, 'localhost')
46
        hostname = get_hostname_by_address('')
47
        self.assertTrue(hostname is '')
48
        hostname = get_hostname_by_address('127.0.0.1111')
49
        self.assertTrue(hostname is '')
50