FreedomBox/plinth/modules/networks/tests/test_privileged.py
Sunil Mohan Adapa 4dda9ad6b9
networks: Use privileged decorator for actions
Tests:

- Initial setup of during first setup works
  - When there are no wired network interfaces
  - When there is 1 wired network interface
    - When there is one wifi interface. wired network is setup as 'external'
      WAN. (simulated with edit of _get_interfaces())
    - When there are no wifi interfaces. wired network is setup as 'internal'
      WAN.
  - When there are multiple wired network interfaces
    - First one is setup as WAN rest as shared
  - When there is one wifi interface, interface is setup as shared.
  - When there are no wifi interfaces

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-10-08 18:52:35 -04:00

29 lines
784 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""Test privileged method for networks app."""
from unittest.mock import patch
from .. import privileged
@patch('subprocess.check_output')
def test_get_interfaces(check_output):
"""Test returning list of network interfaces in sorted order."""
check_output.return_value = '\n'.join([
'ethernet:ve-fbx-testing',
'ethernet:enp39s0',
'ethernet:enp32s1',
'ethernet:enp4s1',
'bridge:virbr0',
'wifi:wlp41s0',
'loopback:lo',
]).encode()
interfaces = privileged._get_interfaces()
assert interfaces == {
'ethernet': ['enp4s1', 'enp32s1', 'enp39s0', 've-fbx-testing'],
'bridge': ['virbr0'],
'wifi': ['wlp41s0'],
'loopback': ['lo']
}