Skip to content

Commit

Permalink
[fix] Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pandafy committed Nov 13, 2024
1 parent c821a2f commit 8dc6d57
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions openwisp_monitoring/device/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class DeviceMetricView(
queryset = (
DeviceData.objects.filter(organization__is_active=True)
.only(
'_is_deactivated',
'id',
'key',
)
Expand Down
5 changes: 5 additions & 0 deletions openwisp_monitoring/device/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ def connect_device_signals(self):
sender=Device,
dispatch_uid='device_deactivated_update_devicemonitoring',
)
device_deactivated.connect(
DeviceMetricView.invalidate_get_device_cache,
sender=Device,
dispatch_uid=('device_deactivated_invalidate_view_device_cache'),
)

@classmethod
def device_post_save_receiver(cls, instance, created, **kwargs):
Expand Down
5 changes: 5 additions & 0 deletions openwisp_monitoring/device/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ def test_deactivated_device_read_only(self):
response = self.client.get(self._url(device.pk, device.key))
self.assertEqual(response.status_code, 200)

# Post should work after the device is activated
device.activate()
response = self._post_data(device.id, device.key, {'type': 'DeviceMonitoring'})
self.assertEqual(response.status_code, 200)

@patch('openwisp_monitoring.device.tasks.write_device_metrics.delay')
def test_background_write(self, mocked_task):
device = self._create_device(organization=self._create_org())
Expand Down

0 comments on commit 8dc6d57

Please sign in to comment.