MCPcopy Create free account
hub / github.com/tiny-pilot/tinypilot / InspectInterfaceTest

Class InspectInterfaceTest

app/network_test.py:12–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10# This test checks the various potential JSON output values that the underlying
11# `ip` command may return.
12class InspectInterfaceTest(unittest.TestCase):
13
14 @mock.patch.object(subprocess, 'check_output')
15 def test_treats_empty_response_as_inactive_interface(self, mock_cmd):
16 mock_cmd.return_value = ''
17 self.assertEqual(
18 network.InterfaceStatus('eth0', False, None, None),
19 network.inspect_interface('eth0'),
20 )
21
22 @mock.patch.object(subprocess, 'check_output')
23 def test_treats_empty_array_as_inactive_interface(self, mock_cmd):
24 mock_cmd.return_value = '[]'
25 self.assertEqual(
26 network.InterfaceStatus('eth0', False, None, None),
27 network.inspect_interface('eth0'),
28 )
29
30 @mock.patch.object(subprocess, 'check_output')
31 def test_treats_emtpy_object_as_inactive_interface(self, mock_cmd):
32 mock_cmd.return_value = '[{}]'
33 self.assertEqual(
34 network.InterfaceStatus('eth0', False, None, None),
35 network.inspect_interface('eth0'),
36 )
37
38 @mock.patch.object(subprocess, 'check_output')
39 def test_disregards_command_failure(self, mock_cmd):
40 mock_cmd.side_effect = mock.Mock(
41 side_effect=subprocess.CalledProcessError(returncode=1, cmd='ip'))
42 self.assertEqual(
43 network.InterfaceStatus('eth0', False, None, None),
44 network.inspect_interface('eth0'),
45 )
46
47 @mock.patch.object(subprocess, 'check_output')
48 def test_parses_operstate_down_as_not_connected(self, mock_cmd):
49 mock_cmd.return_value = """
50 [{"operstate":"DOWN"}]
51 """
52 self.assertEqual(
53 network.InterfaceStatus('eth0', False, None, None),
54 network.inspect_interface('eth0'),
55 )
56
57 @mock.patch.object(subprocess, 'check_output')
58 def test_parses_operstate_up_as_connected(self, mock_cmd):
59 mock_cmd.return_value = """
60 [{"operstate":"UP"}]
61 """
62 self.assertEqual(
63 network.InterfaceStatus('eth0', True, None, None),
64 network.inspect_interface('eth0'),
65 )
66
67 @mock.patch.object(subprocess, 'check_output')
68 def test_parses_mac_address(self, mock_cmd):
69 mock_cmd.return_value = """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected