-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add more helper functions and tests for network configuration wh…
…en running on the raspberry pi
- Loading branch information
Stefano Bertelli
committed
May 15, 2024
1 parent
2938d82
commit a5deac9
Showing
3 changed files
with
101 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
import pprint | ||
import unittest | ||
from unittest.mock import patch, MagicMock | ||
|
||
from jinja2 import Environment, FileSystemLoader, select_autoescape | ||
from rotary_controller_python import network | ||
|
||
from rotary_controller_python.network.models import Wireless, NetworkInterface | ||
from rotary_controller_python.network import reload_interfaces | ||
class TestNetwork(unittest.TestCase): | ||
def test_ifreload(self): | ||
result = network.reload_interfaces() | ||
|
||
def test_ifreload(): | ||
result = reload_interfaces() | ||
@patch('subprocess.run') | ||
def test_read_wlan_status(self, mock_run): | ||
# Example JSON output from rfkill command | ||
example_output = """ | ||
{ | ||
"": [ | ||
{"id":0, "type":"wlan", "device":"phy0", "type-desc":"Wireless LAN", "soft":"unblocked", "hard":"unblocked"}, | ||
{"id":1, "type":"bluetooth", "device":"hci0", "type-desc":"Bluetooth", "soft":"unblocked", "hard":"unblocked"} | ||
] | ||
} | ||
""" | ||
|
||
# Mock the subprocess.run to return the example output | ||
mock_run.return_value = MagicMock( | ||
stdout=example_output.encode('utf-8'), | ||
returncode=0 | ||
) | ||
|
||
from rotary_controller_python.network import read_wlan_status | ||
from rotary_controller_python.network.models import RfkillStatus | ||
|
||
# Call the function to test | ||
result = read_wlan_status() | ||
|
||
# Check that the subprocess.run was called with the correct arguments | ||
mock_run.assert_called_with(["/usr/sbin/rfkill", "-J", "--output-all"], capture_output=True) | ||
|
||
# Check that the result is as expected | ||
expected_result = RfkillStatus( | ||
device="phy0", | ||
id=0, | ||
type="wlan", | ||
soft="unblocked", | ||
hard="unblocked" | ||
) | ||
self.assertEqual(result, expected_result) |