mirror of
https://github.com/MrUnknownDE/OpenIris-ESPIDF.git
synced 2026-04-16 04:53:45 +02:00
Implement tests for changing device mode and MDNS name
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
WIFI_SSID=
|
||||
WIFI_PASS=
|
||||
SWITCH_MODE_REBOOT_TIME=10
|
||||
SWITCH_MODE_REBOOT_TIME=5
|
||||
@@ -114,9 +114,9 @@ def openiris_device_manager(board_connection, config):
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def get_openiris_device(openiris_device_manager):
|
||||
def func():
|
||||
return openiris_device_manager.get_device()
|
||||
def get_openiris_device(openiris_device_manager, config):
|
||||
def func(port: str | None = None, _config: dict | None = None):
|
||||
return openiris_device_manager.get_device(port, config or _config)
|
||||
|
||||
return func
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from tests.utils import has_command_failed
|
||||
import time
|
||||
from tests.utils import has_command_failed, DetectPortChange
|
||||
import pytest
|
||||
|
||||
|
||||
@@ -9,3 +10,52 @@ def test_ping_wired(get_openiris_device, ensure_board_in_mode):
|
||||
|
||||
command_result = device.send_command("ping")
|
||||
assert not has_command_failed(command_result)
|
||||
|
||||
|
||||
@pytest.mark.has_capability("wired")
|
||||
def test_changing_mode_to_wired(get_openiris_device, ensure_board_in_mode):
|
||||
device = get_openiris_device()
|
||||
|
||||
# let's make sure we're in the wireless mode first, if we're going to try changing it
|
||||
device = ensure_board_in_mode("wifi", device)
|
||||
command_result = device.send_command("switch_mode", {"mode": "uvc"})
|
||||
assert not has_command_failed(command_result)
|
||||
|
||||
# to avoid any issues, let's restart the board
|
||||
with DetectPortChange() as port_selector:
|
||||
device.send_command("restart_device")
|
||||
time.sleep(3)
|
||||
|
||||
# and since we've changed the ports
|
||||
device = get_openiris_device(port_selector.get_new_port())
|
||||
# initial read to flush the logs first
|
||||
device.send_command("get_device_mode")
|
||||
result = device.send_command("get_device_mode")
|
||||
assert not has_command_failed(result)
|
||||
|
||||
|
||||
@pytest.mark.has_capability("wireless")
|
||||
def test_setting_mdns_name(get_openiris_device, ensure_board_in_mode):
|
||||
|
||||
def check_mdns_name(name: str):
|
||||
command_result = device.send_command("get_mdns_name")
|
||||
assert not has_command_failed(command_result)
|
||||
assert command_result["results"][0]["result"]["data"]["hostname"] == name
|
||||
|
||||
device = get_openiris_device()
|
||||
device = ensure_board_in_mode("wifi", device)
|
||||
first_name = "testname1"
|
||||
second_name = "testname2"
|
||||
# try setting the test mdns name first, just so we know the commands pass
|
||||
command_result = device.send_command("set_mdns", {"hostname": first_name})
|
||||
assert not has_command_failed(command_result)
|
||||
|
||||
check_mdns_name(first_name)
|
||||
|
||||
command_result = device.send_command("set_mdns", {"hostname": second_name})
|
||||
assert not has_command_failed(command_result)
|
||||
|
||||
device.send_command("restart_device")
|
||||
# let the board boot, wait till it connects
|
||||
time.sleep(3)
|
||||
check_mdns_name(second_name)
|
||||
|
||||
@@ -47,3 +47,19 @@ def get_current_ports() -> list[str]:
|
||||
|
||||
def get_new_port(old_ports, new_ports) -> str:
|
||||
return list(set(new_ports) - set(old_ports))[0]
|
||||
|
||||
|
||||
class DetectPortChange:
|
||||
def __init__(self):
|
||||
self.old_ports = []
|
||||
self.new_ports = []
|
||||
|
||||
def __enter__(self, *args, **kwargs):
|
||||
self.old_ports = get_current_ports()
|
||||
return self
|
||||
|
||||
def __exit__(self, *args, **kwargs):
|
||||
self.new_ports = get_current_ports()
|
||||
|
||||
def get_new_port(self):
|
||||
return get_new_port(self.old_ports, self.new_ports)
|
||||
Reference in New Issue
Block a user