Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions openwisp_controller/connection/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,9 @@ def get_working_connection(
enabled=True,
credentials__connector=connector,
).order_by('-is_working')
# NoWorkingDeviceConnectionError.connection will be
# equal to None if the device has no DeviceConnection.
device_conn = None
for device_conn in qs.iterator():
is_connected = device_conn.connect()
if is_connected:
Expand Down
6 changes: 6 additions & 0 deletions openwisp_controller/connection/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ def test_device_connection_get_working_connection(self, mocked_connect):
org = self._get_org()
device = self._create_device(organization=org)
self._create_config(device=device)

with self.subTest('Test device has no connection object'):
with self.assertRaises(NoWorkingDeviceConnectionError) as error:
conn = DeviceConnection.get_working_connection(device)
self.assertEqual(error.exception.connection, None)

conn1 = self._create_device_connection(
device=device,
credentials=self._create_credentials(organization=org, name='test1'),
Expand Down