Skip to content

Commit b4558b6

Browse files
author
Alex J Lennon
committed
Fix failing tests to use unified device access mocking
- Update test_copy_file_to_device_local_path_not_file to mock get_unified_device_info - Update test_connection_reuse_multiple_transfers to mock get_unified_device_info - Update test_fallback_when_no_ssh_key to mock get_unified_device_info - Update test_get_device_fio_info_success to mock get_unified_device_info returning error - Update test_list_containers_success to mock ssh_to_unified_device directly These tests were failing because the code now uses unified device access (get_unified_device_info, ssh_to_unified_device) instead of directly calling resolve_device_identifier and load_device_config.
1 parent 1bdd628 commit b4558b6

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

tests/test_file_transfer_error_handling.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ def test_copy_file_to_device_local_file_not_found(self, mock_config, mock_resolv
4848
assert "not found" in result["error"].lower()
4949
assert "local" in result["error"].lower()
5050

51-
@patch("lab_testing.tools.file_transfer.resolve_device_identifier")
52-
@patch("lab_testing.tools.file_transfer.load_device_config")
53-
def test_copy_file_to_device_local_path_not_file(self, mock_config, mock_resolve):
51+
@patch("lab_testing.tools.file_transfer.get_unified_device_info")
52+
def test_copy_file_to_device_local_path_not_file(self, mock_get_info):
5453
"""Test error handling when local path is a directory"""
55-
mock_resolve.return_value = "test_device"
56-
mock_config.return_value = {
57-
"devices": {"test_device": {"ip": "192.168.1.1", "ssh_user": "root"}}
54+
mock_get_info.return_value = {
55+
"device_id": "test_device",
56+
"ip": "192.168.1.1",
57+
"username": "root",
58+
"device_type": "local",
5859
}
5960

6061
with tempfile.TemporaryDirectory() as tmpdir:
@@ -217,17 +218,18 @@ def test_copy_files_to_device_parallel_invalid_pairs(self, mock_config, mock_res
217218
class TestMultiplexedConnectionReuse:
218219
"""Test multiplexed SSH connection reuse"""
219220

220-
@patch("lab_testing.tools.file_transfer.resolve_device_identifier")
221-
@patch("lab_testing.tools.file_transfer.load_device_config")
221+
@patch("lab_testing.tools.file_transfer.get_unified_device_info")
222222
@patch("lab_testing.tools.file_transfer.get_persistent_ssh_connection")
223223
@patch("lab_testing.tools.file_transfer.subprocess.run")
224224
def test_connection_reuse_multiple_transfers(
225-
self, mock_subprocess, mock_get_connection, mock_config, mock_resolve
225+
self, mock_subprocess, mock_get_connection, mock_get_info
226226
):
227227
"""Test that multiple transfers reuse the same SSH connection"""
228-
mock_resolve.return_value = "test_device"
229-
mock_config.return_value = {
230-
"devices": {"test_device": {"ip": "192.168.1.1", "ssh_user": "root"}}
228+
mock_get_info.return_value = {
229+
"device_id": "test_device",
230+
"ip": "192.168.1.1",
231+
"username": "root",
232+
"device_type": "local",
231233
}
232234

233235
# Mock persistent connection
@@ -323,17 +325,18 @@ def test_parallel_transfers_share_connection(
323325
finally:
324326
Path(tmpfile_path).unlink()
325327

326-
@patch("lab_testing.tools.file_transfer.resolve_device_identifier")
327-
@patch("lab_testing.tools.file_transfer.load_device_config")
328+
@patch("lab_testing.tools.file_transfer.get_unified_device_info")
328329
@patch("lab_testing.tools.file_transfer.get_persistent_ssh_connection")
329330
@patch("lab_testing.tools.file_transfer.subprocess.run")
330331
def test_fallback_when_no_ssh_key(
331-
self, mock_subprocess, mock_get_connection, mock_config, mock_resolve
332+
self, mock_subprocess, mock_get_connection, mock_get_info
332333
):
333334
"""Test that tools fallback to direct connection when SSH key not installed"""
334-
mock_resolve.return_value = "test_device"
335-
mock_config.return_value = {
336-
"devices": {"test_device": {"ip": "192.168.1.1", "ssh_user": "root"}}
335+
mock_get_info.return_value = {
336+
"device_id": "test_device",
337+
"ip": "192.168.1.1",
338+
"username": "root",
339+
"device_type": "local",
337340
}
338341

339342
# Mock no persistent connection (SSH key not installed)

tests/test_tools_ota.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@
2424
class TestGetDeviceFioInfo:
2525
"""Tests for get_device_fio_info"""
2626

27+
@patch("lab_testing.tools.ota_manager.get_unified_device_info")
2728
@patch("lab_testing.tools.ota_manager.get_lab_devices_config")
2829
@patch("builtins.open")
29-
def test_get_device_fio_info_success(self, mock_open, mock_config, sample_device_config):
30+
def test_get_device_fio_info_success(self, mock_open, mock_config, mock_get_info, sample_device_config):
3031
"""Test getting Foundries.io info for a device"""
32+
# Mock unified device info to return error so it falls back to config
33+
mock_get_info.return_value = {"error": "Device not found in VPN cache"}
3134
mock_config.return_value = sample_device_config
3235
mock_open.return_value.__enter__.return_value.read.return_value = json.dumps(
3336
{
@@ -187,20 +190,23 @@ def test_get_system_status_device_not_found(self, mock_get_info):
187190
class TestListContainers:
188191
"""Tests for list_containers"""
189192

190-
@patch("lab_testing.tools.ota_manager.ssh_to_device")
191-
@patch("lab_testing.tools.ota_manager.get_device_fio_info")
192-
def test_list_containers_success(self, mock_get_info, mock_ssh):
193+
@patch("lab_testing.tools.ota_manager.ssh_to_unified_device")
194+
def test_list_containers_success(self, mock_ssh):
193195
"""Test listing containers successfully"""
194-
mock_get_info.return_value = {"device_id": "test_device_1", "ip": "192.168.1.100"}
195196
mock_ssh.return_value = {
196197
"success": True,
197-
"output": '[{"name": "app-container", "image": "app:1.0.0", "status": "running"}]',
198+
"stdout": "app-container\tUp 2 hours\tapp:1.0.0",
199+
"device_id": "test_device_1",
200+
"device_type": "local",
201+
"connection_method": "direct",
198202
}
199203

200204
result = list_containers("test_device_1")
201205

202206
assert "error" not in result
203207
assert "containers" in result
208+
assert len(result["containers"]) == 1
209+
assert result["containers"][0]["name"] == "app-container"
204210
mock_ssh.assert_called()
205211

206212
@patch("lab_testing.tools.ota_manager.get_device_fio_info")

0 commit comments

Comments
 (0)