예제 #1
0
    def test_user_disabled(self, _, __):
        """Check behavior on user inputs edge-cases"""
        lan_ip = LanIP(options={'max_count': 0})

        output_mock = MagicMock()
        lan_ip.output(output_mock)

        self.assertListEmpty(lan_ip.value)
        self.assertEqual(output_mock.append.call_args[0][1],
                         DEFAULT_CONFIG['default_strings']['no_address'])
예제 #2
0
    def test_netifaces_not_available(self):
        """Check `netifaces` is really acting as a (soft-)dependency"""
        lan_ip = LanIP()

        output_mock = MagicMock()
        lan_ip.output(output_mock)

        self.assertIsNone(lan_ip.value)
        self.assertEqual(output_mock.append.call_args[0][1],
                         DEFAULT_CONFIG['default_strings']['not_detected'])
예제 #3
0
    def test_no_network_address_output(self, _, __):
        """
        Test when the network interface(s) do not have any IP address.
        Additionally check the `output` method behavior.
        """
        lan_ip = LanIP()

        output_mock = MagicMock()
        lan_ip.output(output_mock)

        self.assertListEmpty(lan_ip.value)
        self.assertEqual(output_mock.append.call_args[0][1],
                         DEFAULT_CONFIG['default_strings']['no_address'])
예제 #4
0
    def test_ipv6_and_limit_and_ether(self, _, __):
        """
        Test for IPv6 support, final set length limit and Ethernet interface filtering.
        Additionally check the `output` method behavior.

        IP address "compression" and interface name splitting will also be tested.
        """
        lan_ip = LanIP(options={'max_count': 3})

        output_mock = MagicMock()

        self.assertListEqual(lan_ip.value, [
            '192.168.1.55', '2001::45:6789:abcd:6817',
            'fe80::abcd:ef0:abef:dead'
        ])

        with self.subTest('Single-line combined output.'):
            lan_ip.output(output_mock)
            self.assertEqual(
                output_mock.append.call_args[0][1],
                '192.168.1.55, 2001::45:6789:abcd:6817, fe80::abcd:ef0:abef:dead'
            )

        output_mock.reset_mock()

        with self.subTest('Multi-lines output.'):
            lan_ip.options['one_line'] = False

            lan_ip.output(output_mock)
            self.assertEqual(output_mock.append.call_count, 3)
            output_mock.append.assert_has_calls([
                call('LAN IP', '192.168.1.55'),
                call('LAN IP', '2001::45:6789:abcd:6817'),
                call('LAN IP', 'fe80::abcd:ef0:abef:dead')
            ])
예제 #5
0
    def test_ipv6_and_limit_and_ether(self, _, __):
        """
        Test for IPv6 support, final set length limit and Ethernet interface filtering.
        Additionally check the `output` method behavior.

        IP address "compression" and interface name splitting will also be tested.
        """
        lan_ip = LanIP(options={'max_count': 3})

        output_mock = MagicMock()
        lan_ip.output(output_mock)

        self.assertListEqual(lan_ip.value, [
            '192.168.1.55', '2001::45:6789:abcd:6817',
            'fe80::abcd:ef0:abef:dead'
        ])
        self.assertEqual(
            output_mock.append.call_args[0][1],
            '192.168.1.55, 2001::45:6789:abcd:6817, fe80::abcd:ef0:abef:dead')
예제 #6
0
 def test_show_global(self, _, __):
     """Test public IP addresses forced display"""
     self.assertListEqual(
         LanIP(options={
             'show_global': True
         }).value, ['192.168.1.55', '123.45.67.89'])
예제 #7
0
 def test_multiple_interfaces(self, _, __):
     """Test for multiple interfaces, multiple addresses (including a loopback one)"""
     self.assertListEqual(
         LanIP(options={
             'max_count': False
         }).value, ['192.168.0.11', '192.168.1.11', '172.16.56.78'])
예제 #8
0
 def test_no_network_interface(self, _):
     """Test when the device does not have any network interface"""
     self.assertListEmpty(LanIP().value)
예제 #9
0
 def test_no_ipv6(self, _, __):
     """Test for IPv6 hiding"""
     self.assertListEqual(
         LanIP(options={
             'ipv6_support': False
         }).value, ['192.168.1.55'])