diff --git a/camera/api/viewsets/position_preset.py b/camera/api/viewsets/position_preset.py index aa3fb4f..a899a45 100644 --- a/camera/api/viewsets/position_preset.py +++ b/camera/api/viewsets/position_preset.py @@ -98,10 +98,14 @@ def get_queryset(self): ) if asset_external_id: return queryset.filter( - asset_bed__asset=self.get_asset_obj(asset_external_id) + asset_bed__asset=self.get_asset_obj(asset_external_id), + asset_bed__deleted=False ) if bed_external_id: - return queryset.filter(asset_bed__bed=self.get_bed_obj(bed_external_id)) + return queryset.filter( + asset_bed__bed=self.get_bed_obj(bed_external_id), + asset_bed__deleted=False + ) if self.kwargs.get("external_id"): return queryset.filter(external_id=self.kwargs.get("external_id")) diff --git a/camera/tests/test_camera_preset_apis.py b/camera/tests/test_camera_preset_apis.py index 832c5ef..abfd5c2 100644 --- a/camera/tests/test_camera_preset_apis.py +++ b/camera/tests/test_camera_preset_apis.py @@ -143,7 +143,42 @@ def test_create_camera_preset_with_same_name_in_same_bed(self): ) self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST) - + def test_list_bed_with_deleted_assetbed(self): + res = self.client.post( + self.get_base_url(self.asset_bed1.external_id), + { + "name": "Preset with proper position", + "position": { + "x": 1.0, + "y": 1.0, + "zoom": 1.0, + }, + }, + format="json", + ) + self.assertEqual(res.status_code, status.HTTP_201_CREATED) + res = self.client.post( + self.get_base_url(self.asset_bed2.external_id), + { + "name": "Preset with proper position 2", + "position": { + "x": 1.0, + "y": 1.0, + "zoom": 1.0, + }, + }, + format="json", + ) + self.assertEqual(res.status_code, status.HTTP_201_CREATED) + + res = self.client.get(f"/api/camera/position-presets/?bed_external_id={self.bed.external_id}") + self.assertEqual(len(res.json()["results"]), 2) + + self.asset_bed1.delete() + self.asset_bed1.refresh_from_db() + res = self.client.get(f"/api/camera/position-presets/?bed_external_id={self.bed.external_id}") + self.assertEqual(len(res.json()["results"]), 1) + def test_meta_validations_for_onvif_asset(self): valid_meta = { "local_ip_address": "192.168.0.1",